How to check if double quote character is equal in java

I want to check the char value to make sure it is a double quote or not in Java. How can i do this?

+7
source share
4 answers
if (myChar == '"') { // single quote, then double quote, then single quote System.out.println("It a double quote"); } 

If you want to compare String with another, and check if the other string contains only double quote char, you should avoid double quote with: \

 if ("\"".equals(myString)) { System.out.println("myString only contains a double quote char"); } 
+12
source

If you are dealing with char , just do this:

  c == '"'; 

If c is equal to double quotation marks, the expression will evaluate to true .

So you can do something like this:

 if(c == '"'){ //it is equal }else{ //it is not } 

On the other hand, if you do not have a char variable, but instead of a String object, you should use the equals method and the escape character \ as follows:

 if(c.equals("\"")){ //it is equal }else{ //it is not } 
+6
source

To check the double quote, a string is present, you can use the following code. A double quote has 3 different possible ascii values.

 if(testString.indexOf(8220)>-1 || testString.indexOf(8221)>-1 || testString.indexOf(34)>-1) return true; else return false; 
+4
source

In my case, what am I doing if you want to compare, for example, the response of the server, which should be "OK" , then:

 if (serverResponse.equals("\"OK\"")) { ... } 
+2
source

All Articles