dmp Posted November 15, 2017 Share Posted November 15, 2017 Hi there, I'd like to do pretty much the same function Trim does in excel. Remove any extra spaces inside the data including trailing or leading spaces. I saw someone posted this is possible with "regular expressions"? I can see in the guide book there is left, right or both trim, but not sure how I would go about making a regular expression for removing both and any extra spaces in the data itself. Thanks much for any help! Cheers, Mike Quote Link to comment Share on other sites More sharing options...
step Posted November 15, 2017 Share Posted November 15, 2017 You can do this: return Field("Your Field Name").replace(/\s/g, ''); Quote Link to comment Share on other sites More sharing options...
tim lindner Posted November 15, 2017 Share Posted November 15, 2017 There is also a built-in function: ReplaceSubstring(inputString, fromString, toString): string = ReplaceSubstring(string, " ", ""); Will remove all spaces. Quote Link to comment Share on other sites More sharing options...
dmp Posted November 15, 2017 Author Share Posted November 15, 2017 Awesome thanks guys! I will try that out. Cheers, Mike Quote Link to comment Share on other sites More sharing options...
ThePorge Posted May 3, 2018 Share Posted May 3, 2018 The way I read your question is that you want to remove all leading and trailing spaces and then two or more spaces from inside your string. I'd think the following would do what you'd like. function trimAll(x) { x = x.replace(/^\s*|\s*$/g, ""); x = x.replace(/\s+/g, " "); return x; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.