我有一个字符串
String mystring="[
"28, 4th Cross Road, HAL 3rd Stage, Hal, Puttappa layout, New Thippasandra, Bangalore, Karnataka 560008, Hindistan"
]";
我想做什么 ::
Bangalore
bangalore
逐步遍历我想从中提取bangalore
通过遍历答案 0 :(得分:0)
检查此解决方案,
在这里,我首先在实际数据周围消除包装器([
,]
)。
然后从最后一个搜索关键字
<强>代码强>
public class SO12 {
public static void main(String[] args) {
String mystring = "[\"28, 4th Cross Road, HAL 3rd Stage, Hal, Puttappa layout, New Thippasandra, Bangalore, Karnataka 560008, Hindistan\"]";
mystring = mystring.replace("[", "");
mystring = mystring.replace("]", "");
mystring = mystring.replace("\"", "");
String[] arr = mystring.split(",");
System.out.println(mystring + arr.length);
for (int i = arr.length - 1; i > 0; i--) {
String s = arr[i];
String log = s;
if (s.equalsIgnoreCase(" Bangalore")) {
log = log + "\t found";
}else{
log = log + "\t not found";
}
System.out.println(log);
}
}
}
<强>输出强>
28, 4th Cross Road, HAL 3rd Stage, Hal, Puttappa layout, New Thippasandra, Bangalore, Karnataka 560008, Hindistan9
Hindistan not found
Karnataka 560008 not found
Bangalore found
New Thippasandra not found
Puttappa layout not found
Hal not found
HAL 3rd Stage not found
4th Cross Road not found