Jump to content

Strip a set of characters from a string: Difference between revisions

(added Ursala)
Line 264:
-></pre>
 
=={{header|JJava}}==
<lang java>class StripChars {
'''Solution:'''<br>
public static String stripChars(String inString, String toStrip) {
The dyadic primitive <code>-.</code> ([http://www.jsoftware.com/help/dictionary/d121.htm Less]) is probably the simplest way to solve this task.
return inString.replaceAll("[" + toStrip + "]", "");
}
 
public static void main(String[] args) {
<lang j> ' String sentence = "She was a soul stripper. She took my heart!' -. 'aei'";
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
stripped: Sh ws soul strppr. Sh took my hrt!</langpre>
 
'''Example Usage:'''
<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 )
Cookies help us deliver our services. By using our services, you agree to our use of cookies.