开发者

Getting rid of quotes in a string

开发者 https://www.devze.com 2023-02-18 10:12 出处:网络
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 specifi

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号