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:58, 18 February 2017
, 7 years ago→{{header|Lua}}: previous version doesn't handle pattern character eg. % or - correctly, they should treat as plain character.
(Added Kotlin) |
m (→{{header|Lua}}: previous version doesn't handle pattern character eg. % or - correctly, they should treat as plain character.) |
||
Line 1,173:
<lang lua>
function stripchars(str, chrs)
local s = str:gsub("["..chrs:gsub("%W","%%%1").."]", '')
return s
end
print( stripchars( "She was a soul stripper. She took my heart!", "aei" ) )
--> Sh ws soul strppr. Sh took my hrt!
print( stripchars( "She was a soul stripper. She took my heart!", "a-z" ) )
--> She ws soul stripper. She took my hert!
</lang>
|