#Stringtokenizer not recognizing " as delimiter

13 messages · Page 1 of 1 (latest)

pearl shore
#

StringTokenizer tokenizer = new StringTokenizer(row, "; ()\"", true);
the code correctly separates tokens with spaces, semicolons and parenthesis, but won't separate the quotation marks. Online it says to escape it, which to my understanding is the \" but for some reason when i execute it, it doesn't separate the quotation marks from the rest of the string

manic brambleBOT
#

This post has been reserved for your question.

Hey @pearl shore! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

wet tusk
#

/run

import java.util.StringTokenizer;

public class uu {
    public static void main(String[] args) {
        StringTokenizer tokenizer = new StringTokenizer("a\"b", "; ()\"", true);
        while(tokenizer.hasMoreTokens())
            System.out.println(tokenizer.nextToken());
    }
}

sterile thornBOT
#

Here is your java(15.0.2) output @wet tusk

a
"
b
wet tusk
#

Maybe you're encountering quotation marks with a different unicode value? like ” instead of "

pearl shore
#

i realized that because im reading from an input file, there are no backslashes before the quotation marks, and im guessing that is whats tripping it up

#

its reading from a txt file so i think its the same

wet tusk
#

Backslashes inside your text file wouldn't change anything - \" is just registered as a single " inside a Java String, it's needed otherwise it'd indicate the end of the String.

#

/run

String a = "\"";
System.out.println(a);
sterile thornBOT
#

Here is your java(15.0.2) output @wet tusk

"
pearl shore
#

i put the txt file in my ide and changed the quotation marks and it seems to work now so you were right about the unicode, thanks

manic brambleBOT