AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

quick regexmatch question

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
jlaj1989



Joined: 02 Aug 2008
Posts: 3

PostPosted: Sat Aug 23, 2008 8:49 pm    Post subject: quick regexmatch question Reply with quote

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
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1276

PostPosted: Sat Aug 23, 2008 10:13 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Sat Aug 23, 2008 10:36 pm    Post subject: Reply with quote

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")


Very Happy

Removes spaces at the beginning, end, and around commas.
Back to top
View user's profile Send private message AIM Address
Hasso



Joined: 23 Mar 2005
Posts: 158
Location: Germany

PostPosted: Mon Aug 25, 2008 9:56 am    Post subject: Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Mon Aug 25, 2008 6:08 pm    Post subject: Reply with quote

But he said:
Quote:
also how can i remove trailing spaces between a csv file.


Yours can only remove a set number of one Very Happy
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group