0
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 的输入 ...使用 CODE 包含的 .txt 文件接受输入

.DATA
 DATAENDS

此代码应在单击按钮时执行......

问题:即使@ tok[0] = .DATA它返回的值是假的.....检查了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
4

1 回答 1

2

当你 findequalsequalsIgnoreCase正在返回false时它应该有 return true。用来trim救援。

if(tok[0] != null && tok[0].trim().equalsIgnoreCase(".DATA"))
于 2012-12-28T10:52:21.493 回答