Question

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 :) :)

Était-ce utile?

La solution

try this

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

Autres conseils

StringTokenizer Token1 = new StringTokenizer(file2.replace("\n", ""), " ");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top