Trim end of string

0
Hi all, I want to prevent trailing blanks by trimming the end of strings, but not the beginning so I cannot use ‘trim’.  What is the best way to solve this? Thanks, Frank
asked
2 answers
2

Use the findlast function in combination with the length function to see if the last character is a space. Then you can use the substring to remove that last space.

Regards,

Ronald

 

answered
2

If you are using Community Commons, you can use RegexReplaceAll do this. 

The Needle Regex needs to be 

'(?s)^(.*?)\s*$'

and the Replacement needs to be

'$1'

Use the return variable as this will have the trimmed string.

The regular expression first sets itself up to accept multiple lines, tries to grab and memorise as few characters as possible from the start, and then grab as many spaces as possible from then end. We set the replacement to be those memorised characters, which should be the string you need without any trailing whitespace.

Hope this helps.

answered