int locctr = 0,toknum = 0;
String temp;
String d;
String [] tok = new String[500];
String[] lines = CODE.getText().split("\n");
try
{
for(int i=0;i<lines.length;i++)
{
temp = lines[i];
if(temp != null)
{
StringTokenizer st = new StringTokenizer(lines[i],":,\t[]",true);
while (st.hasMoreTokens())
{
String ss=st.nextToken();
tok[toknum] = ss;
toknum++; //increment
}
}
}
System.out.print("tok[0] is "+tok[0]);
boolean r = tok[0].equalsIgnoreCase(".DATA");
System.out.print("r is : "+r);
if(r == true)
{
System.out.print("\n INSIDE .DATA");
}
}
catch(Exception e)
{
}
//应该接受CODE的输入...它已被使用.txt文件接受 代码包含
.DATA
DATAENDS
这个代码应该在点击按钮时执行......
问题:即使值@ tok[0] = .DATA
返回false .....已检查tok[]
数组,数据正确分配.....
但
条件它仍然给出错误.....
OUTPUT :
temp is .DATA
SS IS .DATA
tok[num] .DATA
toknum 0
temp is DATAENDS
SS IS DATAENDS
tok[num] DATAENDS
toknum 1tok[0] is .DATA
r is : false
答案 0 :(得分:2)
当您发现equals
或equalsIgnoreCase
返回false
时应该返回true
。使用trim
进行救援。
if(tok[0] != null && tok[0].trim().equalsIgnoreCase(".DATA"))