String Replacement

  • Thread starter Thread starter Carl Gilbert
  • Start date Start date
C

Carl Gilbert

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


| 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
|
|
 
crap! i've been programming php for way too long! you'll want to change:

guidVariable . "$2"

to:

guidVariable & "$2"

;^)

happy regex-ing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top