By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,066 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,066 IT Pros & Developers. It's quick & easy.

String Replacement

P: n/a
Hi

I have a script editor and I need to replace sections of the script with
Guids. The script might look something like:

'some text @varUser more text @varClient.Label'

I would like to replace anything that starts with an @ with a Guid.
Therefore I need to search the text for anything that begins @ and ends with
a space or a period.
I can then take this text and replace it with a Guid.

So based on the above example, I would get something like:
Find @, get text after @, find a space, use text to get Guid, replace text
with Guid
@varUser becomes @A91E3B82-15F6-49ED-B7B8-08C706E3940C
Find @, get text after @, find period, use text to get Guid, replace text
with Guid
@varClient.Label becomes @0611222D-A45D-4997-9282-9ED9F8743A70.Label

Does anyone know of any methods or text functions that may help me to
acheive this?

Regards, Carl
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
you can use regex...

the pattern would look something like:

(@[^\s\.]+)([\s\.])

now, if your example looked like:

'some text @varUser'

then @varUser would *not* be replaced since your requirement stated that the
@+text combination either end with a period or a space...which @varUser does
not. if it can end with a space, period *or* be at the end of the line, then
that pattern would look like:

(@[^\s\.]+)([\s\.]|$)

either way, you'd replace using (guidVariable . "$2")...assuming
guidVariable is the guid string.

hth,

me
"Carl Gilbert" <mr*************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
| Hi
|
| I have a script editor and I need to replace sections of the script with
| Guids. The script might look something like:
|
| 'some text @varUser more text @varClient.Label'
|
| I would like to replace anything that starts with an @ with a Guid.
| Therefore I need to search the text for anything that begins @ and ends
with
| a space or a period.
| I can then take this text and replace it with a Guid.
|
| So based on the above example, I would get something like:
| Find @, get text after @, find a space, use text to get Guid, replace text
| with Guid
| @varUser becomes @A91E3B82-15F6-49ED-B7B8-08C706E3940C
| Find @, get text after @, find period, use text to get Guid, replace text
| with Guid
| @varClient.Label becomes @0611222D-A45D-4997-9282-9ED9F8743A70.Label
|
| Does anyone know of any methods or text functions that may help me to
| acheive this?
|
| Regards, Carl
|
|
Nov 21 '05 #2

P: n/a
crap! i've been programming php for way too long! you'll want to change:

guidVariable . "$2"

to:

guidVariable & "$2"

;^)

happy regex-ing.
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.