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?
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?
Please lookup basic Java string manipulation.
A few approaches in Java:
Show us what you’ve tried
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);
}