0

I'm reading a text file that contains a line, e.g. "20 name "Andrew"" and trying to check if the line contains quotation marks after "name" but it returns false when using line.contains("\""). How would I check if the line contains quotation marks with a string between them?

P:S Whenever I print the line out to the console I get: 20 name “Andrew“ but when I check if the line contains "“", it returns false, why is this?

SamTebbs33
  • 5,507
  • 3
  • 22
  • 44
  • You'll need a regular expression if you're checking for any string within quotes. – helion3 Feb 05 '14 at 20:28
  • possible duplicate of [contains quotation mark java](http://stackoverflow.com/questions/16037903/contains-quotation-mark-java) – Raedwald Feb 05 '14 at 21:14

1 Answers1

1

If the console prints “Andrew“, you're probably not using the regular quotation mark. It looks like a fancier unicode quotation, which might look normal (when printed somewhere that supports unicode), but isn't the normal " character. You should go through each character in the String and do

for(int i = 0;i < str.length(); i++)
   System.out.println((int)str.charAt(i));

You'll see the actual unicode value of the characters.

Kayaman
  • 72,141
  • 5
  • 83
  • 121