Strip a set of characters from a string: Difference between revisions
Content added Content deleted
(added Ursala) |
|||
Line 264: | Line 264: | ||
-></pre> |
-></pre> |
||
=={{header| |
=={{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 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 |
|||
⚫ | |||
'''Example Usage:''' |
|||
⚫ | |||
⚫ | |||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
<lang lua>function stripchars( str, chr ) |
<lang lua>function stripchars( str, chr ) |