| View previous topic :: View next topic |
| Author |
Message |
JamesVan
Joined: 01 Oct 2007 Posts: 17
|
Posted: Mon Oct 01, 2007 4:24 pm Post subject: Replace single quote in string variable |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5880
|
Posted: Mon Oct 01, 2007 4:29 pm Post subject: Re: Replace single quote in string variable |
|
|
Should work:
| Code: | | StringReplace, PRJNAME, %PROJECT_NAME%, % Chr(39),, All |
 |
|
| Back to top |
|
 |
JamesVan
Joined: 01 Oct 2007 Posts: 17
|
Posted: Mon Oct 01, 2007 4:35 pm Post subject: |
|
|
| Thanks for the quick reply Skan, but that still gives me the same error. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5880
|
Posted: Mon Oct 01, 2007 5:02 pm Post subject: |
|
|
Please post a sample string.  |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Mon Oct 01, 2007 5:30 pm Post subject: |
|
|
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 |
|
 |
JamesVan
Joined: 01 Oct 2007 Posts: 17
|
Posted: Mon Oct 01, 2007 6:23 pm Post subject: |
|
|
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 |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Mon Oct 01, 2007 6:28 pm Post subject: |
|
|
| 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 |
|
 |
JamesVan
Joined: 01 Oct 2007 Posts: 17
|
Posted: Mon Oct 01, 2007 6:32 pm Post subject: |
|
|
| engunneer wrote: | | Code: |
EnvGet, PRJNAME, PROJECT_NAME
StringReplace, PRJNAME, PRJNAME, ',, All
;PRJNAME := RegExReplace(%PROJECT_NAME%, "'", "")
|
|
That did it! Thanks a million! |
|
| Back to top |
|
 |
|