Strip a set of characters from a string

func stripchars(str, char_list) {
    str.tr(char_list, "", "d")
}

or:

func stripchars(str, char_list) {
    str.chars.grep {|c| !char_list.contains(c)}.join
}

Calling the function:

say stripchars("She was a soul stripper. She took my heart!", "aei")

Output:

Sh ws  soul strppr. Sh took my hrt!

Last updated