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

Content added Content deleted
(added Ursala)
Line 264: Line 264:
-></pre>
-></pre>


=={{header|J}}==
=={{header|Java}}==
<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) {
String sentence = "She was a soul stripper. She took my heart!";
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!</pre>


'''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}}==
=={{header|Lua}}==
<lang lua>function stripchars( str, chr )
<lang lua>function stripchars( str, chr )