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

m
→‎{{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>
 
Anonymous user