07-18-2023, 09:24 PM
My personal preference is using the method `.tr`
as in:
string = "this is a string to smash together"
string.tr(' ', '') # => "thisisastringtosmashtogether"
Thanks to @FrankScmitt for pointing out that to make this delete _all_ whitespace(not just spaces) you would need to write it as such:
string = "this is a string with tabs\t and a \nnewline"
string.tr(" \n\t", '') # => "thisisastringwithtabsandanewline"
as in:
string = "this is a string to smash together"
string.tr(' ', '') # => "thisisastringtosmashtogether"
Thanks to @FrankScmitt for pointing out that to make this delete _all_ whitespace(not just spaces) you would need to write it as such:
string = "this is a string with tabs\t and a \nnewline"
string.tr(" \n\t", '') # => "thisisastringwithtabsandanewline"