Anonymous user
Strip a set of characters from a string: Difference between revisions
Strip a set of characters from a string (view source)
Revision as of 20:53, 12 August 2011
, 12 years ago→{{header|J}}
(added Ursala) |
|||
Line 264:
-></pre>
=={{header|
<lang java>class StripChars {
public static String stripChars(String inString, String toStrip) {
return inString.replaceAll("[" + toStrip + "]", "");
}
public static void main(String[] args) {
String chars = "aei";
System.out.println("sentence: " + sentence);
System.out.println("to strip: " + chars);
System.out.println("stripped: " + stripChars(sentence, chars));
}
}</lang>
output:
<pre>sentence: She was a soul stripper. She took my heart!
to strip: aei
▲<lang j> 'She was a soul stripper. She took my heart!' -. 'aei'
▲Sh ws soul strppr. Sh took my hrt!</lang>
=={{header|Lua}}==
<lang lua>function stripchars( str, chr )
|