【发布时间】:2011-08-08 06:36:46
【问题描述】:
我正在尝试做一些非常简单但在 android 中显然非常困难的事情。 我只是想比较两个字符串,看看它们是否相等。
我有一个值为“位置”的临时变量 我已经调试过了,它确实包含位置... 所以我一开始就尝试了这个
if(temp == "Location") { //do something }
但我已经知道这行不通。然后我尝试了所有可能的字符串函数,例如:
.等于 .包含 .ignoreCaseEquals 等等……
如果有人知道该怎么做,请帮忙。这真的很烦人。
编辑: 这是我为想要查看的人比较字符串的函数。
public String[] getData(){
try {
int tempGroupCount = 0;
URL food_url = new URL (Constants.SERVER_DINING);
BufferedReader my_buffer = new BufferedReader(new InputStreamReader(food_url.openStream()));
temp = my_buffer.readLine();
// prime read
while (temp != null ){
// check to see if readline equals Location
Log.w("HERasdfsafdsafdsafE", temp);
// start a new location
if (temp.equals("Location")
{
groups[tempGroupCount] = temp;
tempGroupCount++;
}
Log.w("HERasdfsafdsafdsafE", temp);
//start for-loop to test to get child info
//for(temp = my_buffer.readLine(); temp != "Location" && temp != null; groupCount++, childrenCount++){
//children[groupCount][childrenCount] = temp;
//}
temp = my_buffer.readLine();
}
my_buffer.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("IO EXCEPTION", "Exception occured in MyExpandableListAdapter:" + e.toString());
}
return groups;
}
【问题讨论】:
-
equals不起作用怎么办? -
也许这会有所帮助(也许):stackoverflow.com/questions/4210713/…
标签: java android string compare