Java detect double double quotes in String

30,606

You are checking for 2 "(double quotes)s while your string has only one in the beginning. Try below:

 test.startsWith("\"");
 test.endsWith("\"");

Should work.

Share:
30,606
JAB
Author by

JAB

Updated on July 09, 2022

Comments

  • JAB
    JAB almost 2 years

    Sample Code

    public static void main(String args[]){  
    String test=null;   
    if(some condition)  
       test = "\"abc\"";
    else
       test ="def";
    
    // if condition is true , in debug mode when i check the value of test its ""abc"" (double double quote);   
    // if condition is false , then value of test is "def" (double quotes only one time);
    
    
    }
    

    Looking for a logic to check whether string has double double quotes . Tried below stuff

    // test.startsWith("\"\""))  // this didn;t work
    
  • Shajeel Afzal
    Shajeel Afzal over 7 years
    Thanks, How to remove these?
  • Yogendra Singh
    Yogendra Singh over 7 years
    You can use replaceAll method.