字符串处理,根据传入的参数进行分离,目前较适合字符串中提取引号包裹的部分的提取

xiaoxiao2021-02-27  251



import java.util.ArrayList;

import java.util.List;

public class Test {  public static List<String> spiltMark(String sentence, List<String> li,    String args) {   while (true) {    if (sentence.indexOf(args) > -1) {     int b = sentence.indexOf(args);     int a = sentence.substring(b + 1).indexOf(args);     if (a == -1) {      break;     } else {      String c = sentence.substring(b + 1, a);      li.add(c);     }

    sentence = sentence.substring(a + 1);

   } else {     break;    }   }   return li;  }

 public static void main(String[] args) {   List<String> list = new ArrayList<String>();   String s = "'kjdsandlkc'smxz,\"KXSKCL'DFASDFSAS'";   list = spiltMark(s, list, "'");   System.out.println(list);  }

}

转载请注明原文地址: https://www.6miu.com/read-10155.html

最新回复(0)