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
#Stringtokenizer not recognizing " as delimiter
13 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @pearl shore! Please use
/closeor theClose Postbutton 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.
/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());
}
}
Here is your java(15.0.2) output @wet tusk
a
"
b
Maybe you're encountering quotation marks with a different unicode value? like ” instead of "
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
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);
Here is your java(15.0.2) output @wet tusk
"
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
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.