我想获取某个给定字符串之间的字符串
像这样..
String wholetext = "SomePlace Pin- 110065 Name and address Alias 1 ID of customer-123 SomePlace "
String namerequired = "";
String textafter = "110065 Name and address";
String textbefore = "ID of customer";
//Constant part-110065 Name and address and ID of customer
谷歌搜索并得到类似这样的东西doindexing 还有这个doindexing1
我正在尝试获取 Alias 1 但不明白:( ? 请帮忙
最佳答案
这应该可以解决您的问题:
String wholetext = "Place Then Pin- **110065 Name and address** Alias 1 ID of customer-123 Some Place ";
String textafter = "110065 Name and address";
String textbefore = "ID of customer";
int index1 = wholetext.indexOf(textbefore);
int index2 = wholetext.indexOf(textafter) + textafter.length();
String namerequired = wholetext.substring(index2, index1);
System.out.println(namerequired);
输出:
Alias 1
但是使用正则表达式或字符串匹配器可能会更好。
关于java - 如何获取某个字符串之间的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25521190/