Page 1 of 1
Trim white spaces
Posted: 23 Dec 2012 09:47
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.
Re: Trim white spaces
Posted: 23 Dec 2012 14:33
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.
Re: Trim white spaces
Posted: 23 Dec 2012 16:13
by highend
I would have used this expression:
Code: Select all
regexreplace($Input, "\s{2,}", " ");
Re: Trim white spaces
Posted: 23 Dec 2012 21:16
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.
Re: Trim white spaces
Posted: 23 Dec 2012 21:41
by highend
Code: Select all
foreach($file, <get SelectedItemsPathNames>, "<crlf>") {
rename r, "\s{2,} > ", , $file;
}
Re: Trim white spaces
Posted: 23 Dec 2012 22:18
by JimXYUser
foreach($file, <get SelectedItemsPathNames>, "<crlf>") {
rename r, "\s{2,} > ", , $file;
}
very good! thanks.