JAVA 用subString()截取字符串

aaa bbb ccc ddd eee 怎么样用subString截取ccc ddd eee?
2024-11-29 01:55:07
推荐回答(2个)
回答(1):

String a="aaa bbb ccc ddd eee ";
String b=a.substring(0,3);
String c=a.substring(4,7);
String d=a.substring(8,11);
String e=a.substring(12,15);
String f=a.substring(16,19);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println(f);

——————————————————————————
像这种有特定格式的可以用split更方便

String a="aaa bbb ccc ddd eee ";
String [] b=a.split(" ");
for (int i = 0; i < b.length; i++) {
System.out.println(b[i]);
}
已空格为分隔符截取出一个数组

不准可追问,望采纳

回答(2):

String s="aaa bbb ccc ddd eee".substring(8,"aaa bbb ccc ddd eee".length())