Java Split截取字符串的各种方法示例

public class SplitDemo2 {

public static String[] ss = new String[20];

public SplitDemo2() {

// String s = "The rain in $$$$ Spain falls mainly in the plain.";
  String s = "XXXXX$$$$YYYYY";
  // 在每个空格字符处进行分解。
  // ss = s.split(" ",4);

// 在每个空格字符处进行分解。
  // ss = s.split(" ",20);
  ss = s.split(" ", 5);

// String[] cut = s.split("$$$$");
  // String[] cut = sName1.split("$$$$")+"$$$$";

}

public static void main(String[] args) {
  SplitDemo2 demo = new SplitDemo2();
  for (int i = 0; i < ss.length; i++)
   System.out.print(ss[i]);

String value = "192.168.128.33";
  String[] names = value.split("\\.");
  for (int i = 0; i < names.length; i++) {
   System.out.print(names[i]);
  }

String longString = "aa:bb:cc";
  String[] shortString = longString.split(":");
  for (int i = 0; i < shortString.length; i++) {
   System.out.println(shortString[i]);
  }

String s = "XXXXX$$$$YYYYY";
  String[] cut = s.split("\\$\\$\\$\\$");
  for (String rs : cut) {
   System.out.println(rs);
  }

// StringReader in1 = new StringReader(s);
  // int c;
  // while((c = in1.read()) != -1)
  // System.out.print((char)c);

// String[] ss=new String[20];
  // ss = sName1.split("$$$$");
  // for(int j=0;j<ss.length;j++)
  // System.out.println(ss[j]);

}

}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwpjzx.html