문제

StringTokenizer Token1 = new StringTokenizer(file2," ");
    while(Token1.hasMoreTokens()) {
        String word = Token1.nextToken();
        if(word.equals(Query1)){
            x =1;
            System.out.println("help");
        }else if(word.equals(Query2)){
            y =1;
        }

This is my code, it splits the string fine but the last token always has a \n and when I try to compare the last token with a value it should be it fails.

enter image description here

Thank you .trim() work perfectly :) :)

도움이 되었습니까?

해결책

try this

StringTokenizer Token1 = new StringTokenizer(file2.trim(), " ");
...

다른 팁

StringTokenizer Token1 = new StringTokenizer(file2.replace("\n", ""), " ");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top