0

The user input a String through the scanner and the format of String is "Testing" (quoted with “”) . Just like C:\> "Testing"

I'd like to save the text as a String without double quotes. How do I catch the text in the middle of quotes?

Tik
  • 9
  • 2
  • 1
    You can escape quotation marks with a backslash – milt_on Mar 16 '19 at 08:59
  • 1
    Possible duplicate of [How can I make Java print quotes, like "Hello"?](https://stackoverflow.com/questions/3844595/how-can-i-make-java-print-quotes-like-hello) – milt_on Mar 16 '19 at 09:01
  • Do you want to remove all the quotes, or get the string in the double quotes and discard what is not? What should happen when there is no quotes? – Snowy_1803 Mar 16 '19 at 10:12

2 Answers2

0

Please lookup basic Java string manipulation.

A few approaches in Java:

  1. Use .substring(1, length-1)
  2. Use .replaceAll(“\”,””)
  3. Use regular expression in Java and extract contents between “(.*)”

Show us what you’ve tried

Joey Pinto
  • 1,735
  • 1
  • 18
  • 34
0

If the double quotes are always present at the start and end Then

s= s.substring(1,s.length()-1);

else you can try

if(s.charAt(0)=='"'){
       s=s.substring(1,s.length());
   }
   if(s.charAt(s.length()-1)=='"'){
       s=s.substring(0,s.length()-1);
   }
shivendra
  • 1
  • 1