| View previous topic :: View next topic |
| Author |
Message |
jlaj1989
Joined: 02 Aug 2008 Posts: 3
|
Posted: Sat Aug 23, 2008 8:49 pm Post subject: quick regexmatch question |
|
|
I think ive got the hang of this regexmatch but i cant figure out how to remove trailing spaces. How can i remove the trailing spaces with removing all the spaces?
| Code: | | THIS IS A BUNCH OF TEXT |
and make it do this.
| Code: | | THIS IS A BUNCH OF TEXT |
also how can i remove trailing spaces between a csv file.
| Code: | | THIS IS A BUNCH OF TEXT, MORE TEXT |
and make it do this.
| Code: | | THIS IS A BUNCH OF TEXT,MORE TEXT |
any help would be great thanks. |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1276
|
Posted: Sat Aug 23, 2008 10:13 pm Post subject: |
|
|
You can remove trailing spaces by assigning the variable to itself. See AutoTrim for more info.
| Code: | string := " trailing spaces "
msgbox "%string%"
string = %string% ; remove the trailing spaces
msgbox "%string%" |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Sat Aug 23, 2008 10:36 pm Post subject: |
|
|
Although what Serenity posted is true, you can't remove the spaces around the commas like that. Sooo...
| Code: | String := " THIS IS A BUNCH OF TEXT, MORE TEXT"
RegExReplace(String, "(^ +| +$|(?: +)?(,)(?: +)?)","$2") |
Removes spaces at the beginning, end, and around commas. |
|
| Back to top |
|
 |
Hasso
Joined: 23 Mar 2005 Posts: 158 Location: Germany
|
Posted: Mon Aug 25, 2008 9:56 am Post subject: |
|
|
Couldn't it be done without RegEx by simply adding a line to Serenity's script? | Code: | string := " trailing spaces "
msgbox "%string%"
string = %string% ; remove the trailing spaces
StringReplace, string , string , `,%A_SPACE%, `,, A ; remove spaces after commas
msgbox "%string%" |
_________________ Hasso
Programmers don't die, they GOSUB without RETURN |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Mon Aug 25, 2008 6:08 pm Post subject: |
|
|
But he said:
| Quote: | | also how can i remove trailing spaces between a csv file. |
Yours can only remove a set number of one  |
|
| Back to top |
|
 |
|