java - double quotes and the split method


Keywords:java 


Question: 

I am trying to split a large String using double quotations "\"" as the delimiter. For some reason, the split method doesn't seem able to locate occurrences of double quotes in my String. Code:

    public void stripToDialog()
    {
        String[] parsedContent = content.split("\"");//content has a very large String stored in it.

        for(String e: parsedContent)//When I print each element out, I only get the original String stored in content.
            System.out.println(e);
    }

So what is going on? How come the split method can't seem to detect double quotes?

An example for my desired results for a dummy String of "\"hasta la vista baby\" - Arnold S." would be an array of Strings that looks like: {"", "hasta la vista baby", " - Arnold S."}

In case it matters, I read the original String from a txt file using a FileReader object.


1 Answer: 

I agree with the other posters, your quotes are probably fancy Unicode quotes.

I guess one fix might be to take your input string and replace all "fancy" quotes with regular ones.

content.replaceAll( "\\u0093", "\"" );
content.replaceAll( "\\u0094", "\"" );

You might want to take a look at this page to see what other quotes you might have to handle :