How to split string into paragraphs using first comma?

前端 未结 4 474
谎友^
谎友^ 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:20

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

    #{@address[0, break_at]}

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

    "

提交回复
热议问题