我想检查字符串的哪一部分等于文本,从第0部分到count
。
所以我尝试了这个:
int count = 1;
int city = 0;
String finall = "gggg,dddd";
String[] separated = finall.split(",");
for (int i = 0; i < count; ++i)
if (selectedCities.equals(separated[i])){
city = 1;
}
如何在每次1合1时增加i,直到达到count
的值?
答案 0 :(得分:0)
我想您想像这样实现:
String selectedCities = "Miami"; // Selected(Predefine) city
int count = 0;
int city = 0;
String finall = "California,Miami,Delawar,New Jursey";
String[] separated = finall.split(",");
count = separated.length; // find total city in array
for (int i = 0; i < count; ++i){
if (selectedCities.equals(separated[i])){
city = 1;
}
}
System.out.println("City Count = "+city); //Here count will be 1
希望这会有所帮助