Split string into 2 strings based on a delimiter

后端 未结 3 1059
迷失自我
迷失自我 2020-12-17 17:48

Does anybody know if there is a solid library based method to achieve the following.

Say I have the string

\"name1, name2, name3, name4\" 
         


        
3条回答
  •  心在旅途
    2020-12-17 18:29

    Pattern pattern = Pattern.compile(", *");
    Matcher matcher = pattern.matcher(inputString);
    if (matcher.find()) {
        string1 = inputString.substring(0, matcher.start());
        string2 = inputString.substring(matcher.end());
    }
    

提交回复
热议问题