-2

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.

Isaac Yates
  • 83
  • 1
  • 6
  • 3
    Post a complete minimal example reproducing the problem. Mine doesn't: https://gist.github.com/jnizet/ac5e53d5971a4af436494b5cc52586d5. My guess is that your string doesn't contain double quotes, but "smart", "curly" double quotes as many word processors include when typing a double quote. – JB Nizet Apr 07 '16 at 20:47
  • Works just fine for me... – austin wernli Apr 07 '16 at 20:49
  • 1
    “ " ” These 3 characters are not the same characters, Maybe you have one of them in your content – Yusuf K. Apr 07 '16 at 20:53
  • Thanks! I'm pretty sure that the quotes in String aren't regular quotes. I was comparing them in my editor and they look different. – Isaac Yates Apr 07 '16 at 20:57

1 Answers1

0

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 : https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html

Javed Ahamed
  • 2,804
  • 6
  • 32
  • 41