M
Mike
Ok, heres a tuff one:
How do I remove all quote characters, i.e, " from a string?
How do I remove all quote characters, i.e, " from a string?
Mike said:Ok, heres a tuff one:
How do I remove all quote characters, i.e, " from a string?
How do I remove all quote characters, i.e, " from a string?
String aStringWithNoQuotes = aStringWithQuotes.replaceAll("\"","");
Roedy Green said:You don't replaceAll, just plain replace. ReplaceAll is the regex
version. You want the simple replace( String, String). You can't use
the even faster replace( char, char ) since your you are replacing
with nothing not a char.
Ok, heres a tuff one:
How do I remove all quote characters, i.e, " from a string?
replaceAll worked for me where as "replace" did not.
suppose you string with quote characters is "aStringWithQuotes":
String aStringWithNoQuotes = aStringWithQuotes.replaceAll("\"","");
I noticed that the string class has a couple of methods that the Matcher
class has, namely replaceAll() and replaceFirst().
Does the String class use the Matcher class internaly since it can
accept regular expressions or does it use a private mechanism?
I would think the first is the correct one?
Roedy Green said:You can answer those questions by looking at the source in src.zip.
Most IDEs will show it two you in a keystroke or two.
It will show you the code:
public String replaceAll(String regex, String replacement) {
return Pattern.compile(regex).matcher(this).replaceAll(replacement);
You can see String.replaceAll is just a convenience wrapper that
re-compiles the Pattern every time you use it.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.