我有一个字符串,其中包含 2 个由空格分隔的整数,后跟任何包含空格的字符串。
示例:
23 14 this is a random string
如何提取这是一个随机字符串
?
不能保证整数是两位数,因此我无法弄清楚如何使用 indexOf 和子字符串来提取此数据。
提前致谢。
最佳答案
使用split(String regex, int limit)
:
String s = "23 14 this is a random string";
String[] arr = s.split(" ", 3);
System.out.println(arr[2]);
输出:
this is a random string
关于java - 提取字符串,包括字符串中的空格(java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11463878/