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

Was it helpful?

Solution

try this

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

OTHER TIPS

StringTokenizer Token1 = new StringTokenizer(file2.replace("\n", ""), " ");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top