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 

Replace single quote in string variable

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



Joined: 01 Oct 2007
Posts: 17

PostPosted: Mon Oct 01, 2007 4:24 pm    Post subject: Replace single quote in string variable Reply with quote

I'm trying to grab an environment variable we have which is a string, but it enclosed in single quotes. (e.g. 'Training Project'). I want to grab it and remove the single quotes using either StringReplace or RegExReplace, but I keep getting an error that the variable contains an illegal character. Here are two options I've been trying:

Code:
StringReplace, PRJNAME, %PROJECT_NAME%, Chr(39),, All
PRJNAME := RegExReplace(%PROJECT_NAME%, "'", "")


%PROJECT_NAME% is the environment variable, PRJNAME is the variable I created to catch the trimmed string.

Many thanks for any help.

James V
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5880

PostPosted: Mon Oct 01, 2007 4:29 pm    Post subject: Re: Replace single quote in string variable Reply with quote

Should work:

Code:
StringReplace, PRJNAME, %PROJECT_NAME%, % Chr(39),, All


Smile
Back to top
View user's profile Send private message
JamesVan



Joined: 01 Oct 2007
Posts: 17

PostPosted: Mon Oct 01, 2007 4:35 pm    Post subject: Reply with quote

Thanks for the quick reply Skan, but that still gives me the same error.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5880

PostPosted: Mon Oct 01, 2007 5:02 pm    Post subject: Reply with quote

Please post a sample string. Smile
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Mon Oct 01, 2007 5:30 pm    Post subject: Reply with quote

Are you using EnvGet?
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
JamesVan



Joined: 01 Oct 2007
Posts: 17

PostPosted: Mon Oct 01, 2007 6:23 pm    Post subject: Reply with quote

No, I'm not using EnvGet. Should I get the variable with that first?

A sample value would be 'Training Project' (the single quotes included).
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Mon Oct 01, 2007 6:28 pm    Post subject: Reply with quote

Code:

EnvGet, PRJNAME, PROJECT_NAME
StringReplace, PRJNAME, PRJNAME, ',, All
;PRJNAME := RegExReplace(%PROJECT_NAME%, "'", "")

_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
JamesVan



Joined: 01 Oct 2007
Posts: 17

PostPosted: Mon Oct 01, 2007 6:32 pm    Post subject: Reply with quote

engunneer wrote:
Code:

EnvGet, PRJNAME, PROJECT_NAME
StringReplace, PRJNAME, PRJNAME, ',, All
;PRJNAME := RegExReplace(%PROJECT_NAME%, "'", "")


That did it! Thanks a million!
Back to top
View user's profile Send private message
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