Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 14th, 2017, 04:06 PM
dmp dmp is offline
Junior Community Member
 
Join Date: Oct 2009
Posts: 42
Default How to trim spaces inside data values

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
Reply With Quote
  #2  
Old November 15th, 2017, 05:40 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: How to trim spaces inside data values

You can do this:
Code:
return Field("Your Field Name").replace(/\s/g, '');
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old November 15th, 2017, 07:44 AM
tim lindner tim lindner is offline
Forum n00b
 
Join Date: Oct 2013
Posts: 6
Default Re: How to trim spaces inside data values

There is also a built-in function: ReplaceSubstring(inputString, fromString, toString):

Code:
string = ReplaceSubstring(string, " ", "");
Will remove all spaces.
Reply With Quote
  #4  
Old November 15th, 2017, 09:23 AM
dmp dmp is offline
Junior Community Member
 
Join Date: Oct 2009
Posts: 42
Default Re: How to trim spaces inside data values

Awesome thanks guys! I will try that out.
Cheers,
Mike
Reply With Quote
  #5  
Old May 3rd, 2018, 08:21 AM
ThePorge ThePorge is offline
Regular Contributor
 
Join Date: Aug 2011
Location: Georgia
Posts: 59
Default Re: How to trim spaces inside data values

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.
Quote:
function trimAll(x) {
x = x.replace(/^\s*|\s*$/g, "");
x = x.replace(/\s+/g, " ");
return x;
}
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:24 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.