Remove one or multiple substring from the end of a string -- default: remove whitespace characters

string:trim_end(STRING string
, remove: [ " ", "\t", "\n", "\r", "", "\v" ]
, INT limit: 0) : STRING

string:trim_end(" hi ")
#=> " hi"

string:trim_end("hi   ")
#=> "hi"

string:trim_end("hi \n\n  ")
#=> "hi"

string:trim_end("foo...",".")
#=> "foo"

# trim multiple strings
string:trim_end(".foo...",['.','o'])
#=> ".f"

# trim only maximum of 2 occurences from end of string
# note: by default, $limit = 0 means no-limit
string:trim_end(".foo...",['.'],2)
#=> ".foo."

string:trim_end("foo...",'.', 2)
#=> "foo."

string:trim_end("foo...",'...')
#=> "foo"

# remove string
string:trim_end("bar foofoofoo",'foo') 
#=> "bar "

# remove maximum of 2 from end of string
string:trim_end("foobar foofoofoo",'foo',2) 
#=> "foobar foo"

string:trim_end("bar nice foofoobarfoo",['foo','bar'],2) 
#=> "bar nice foofoo"

Copyright ©2013-2022 SunSed®. All rights reserved.