Remove one or multiple substring from the beginning and end of a string -- default: remove whitespace characters
string:trim(STRING $string, $remove=[ " ", "\t", "\n", "\r", " ", "\v" ], INT $limit=0) : STRING
string:trim(" hi ")
#=> "hi"
string:trim("hi ")
#=> "hi"
string:trim("hi \n\n ")
#=> "hi"
string:trim("foo...",".")
#=> "foo"
# trim multiple strings
string:trim("foo...",['.','o'])
#=> "f"
# trim only maximum of 2 occurences from each side
# note: by default, $limit = 0 means no-limit
string:trim("foo...",['.'],2)
#=> "foo."
string:trim("foo...",'.', 2)
#=> "foo."
string:trim("foo...",'...')
#=> "foo"
# remove string
string:trim("bar foofoofoo",'foo')
#=> "bar "
# remove maximum of 2 from each side
string:trim("foobar foofoofoo",'foo',2)
#=> "bar foo"
#=> "bar foo"
string:trim("bar nice foofoofoo",['foo','bar'],2)
#=> " nice foo"
Copyright ©2013-2022 SunSed®. All rights reserved.