How do I split a string, breaking at a particular character?

后端 未结 17 2436
误落风尘
误落风尘 2020-11-21 05:07

I have this string

\'john smith~123 Street~Apt 4~New York~NY~12345\'

Using JavaScript, what is the fastest way to parse this into



        
17条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 05:24

    You don't need jQuery.

    var s = 'john smith~123 Street~Apt 4~New York~NY~12345';
    var fields = s.split(/~/);
    var name = fields[0];
    var street = fields[1];
    

提交回复
热议问题