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



import java.util.ArrayList;

import java.util.List;

public class Test {
 public static List spiltMark(String sentence, List 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 list = new ArrayList();
  String s = "'kjdsandlkc'smxz,\"KXSKCL'DFASDFSAS'";
  list = spiltMark(s, list, "'");
  System.out.println(list);
 }

}

你可能感兴趣的:(字符串处理,根据传入的参数进行分离,目前较适合字符串中提取引号包裹的部分的提取)