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

后端 未结 17 2430
误落风尘
误落风尘 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:41

    If Spliter is found then only

    Split it

    else return the same string

    function SplitTheString(ResultStr) {
        if (ResultStr != null) {
            var SplitChars = '~';
            if (ResultStr.indexOf(SplitChars) >= 0) {
                var DtlStr = ResultStr.split(SplitChars);
                var name  = DtlStr[0];
                var street = DtlStr[1];
            }
        }
    }
    

提交回复
热议问题