Pregunta

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

¿Fue útil?

Solución

try this

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

Otros consejos

StringTokenizer Token1 = new StringTokenizer(file2.replace("\n", ""), " ");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top