How to split string into paragraphs using first comma?

前端 未结 4 466
谎友^
谎友^ 2021-02-05 01:30

I have string: @address = \"10 Madison Avenue, New York, NY - (212) 538-1884\" What\'s the best way to split it like this?

10 Madison Avenu

4条回答
  •  借酒劲吻你
    2021-02-05 02:28

    rather:

    break_at = @address.index(", ")
    result = "

    #{@address[0, break_at+1]}

    #{@address[break_at+1..-1]}

    "

提交回复
热议问题