Trim white spaces

Discuss and share scripts and script files...
Post Reply
JimXYUser
Posts: 23
Joined: 23 Nov 2012 00:26

Trim white spaces

Post by JimXYUser »

In script, how to trim more then 1 white space into just one.

e.g.

Code: Select all

From : "I  have   many    white    spaces."                [Note: many spaces in between]

To    : "I have many white spaces."                         [Note: Become, only 1 space in between ]
thanks.

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Trim white spaces

Post by SkyFrontier »

This is a neverending torment to me, Jim.

Try this:

Code: Select all

 $Input = "I  not    have   many    white    spaces    , anymore.";  $b = regexreplace($Input, "( +)", " "); text $b;
Credit goes to someone else I can't find for now who helped me on this.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 14942
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Trim white spaces

Post by highend »

I would have used this expression:

Code: Select all

regexreplace($Input, "\s{2,}", " ");
One of my scripts helped you out? Please donate via Paypal

JimXYUser
Posts: 23
Joined: 23 Nov 2012 00:26

Re: Trim white spaces

Post by JimXYUser »

Sorry for not making myself clear, i would like to put the above script to rename some files that have many white spaces.

How do i do that, as right now, the script prompt for input and i don't know how to turn $Input into file name.

thanks for the help.

highend
Posts: 14942
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Trim white spaces

Post by highend »

Code: Select all

    foreach($file, <get SelectedItemsPathNames>, "<crlf>") {
        rename r, "\s{2,} >  ", , $file;
    }
One of my scripts helped you out? Please donate via Paypal

JimXYUser
Posts: 23
Joined: 23 Nov 2012 00:26

Re: Trim white spaces

Post by JimXYUser »

foreach($file, <get SelectedItemsPathNames>, "<crlf>") {
rename r, "\s{2,} > ", , $file;
}
very good! thanks.

Post Reply