Hi I have a string with quotation marks
String s = "\"hello\"";
and I was wondering how to get rid of the quotes in the string s. Is ther开发者_Go百科e a method that can get rid of a specific char? Something like s.getRidofChar(");
Is this what you are looking for:
s = s.replaceAll("\"", "");
The \
is because we have to escape the quotes. This is saying we will replace all instances of quotes with the empty string. Remember that String
is immutable, so we need to assign the value returned by replaceAll
back to s
(or some other variable).
String s = "\"hello\"";
s = s.replaceAll("\"","")
Edit: Try replaceAll method.
You can use String.replaceAll() with an empty replacement string.
If you want to remove a certain character at a certain position, take the substring before and after the character and join them together.
精彩评论