Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace whole word 1

Status
Not open for further replies.

draigGoch

Programmer
Feb 10, 2005
166
GB
Does anyone know of any replace whole word functions for ASP?
I can't seem to find any on the net - and i know other people must have been in this situation before. I want to replace all instances of a word - but only the whole word.

Example:
Search for "tone"

replaces "tone", "tone.", "Tone", "Tone,"
but not "stone", "toned"

I have no idea on how to do this.... help please!
Do i need to use regular expressions (and if so - help again!!)



A computer always does what you tell it to, but rarely does what you want it to.....
 
Put a space either side of tone. In other words use " tone " as your search string instead of "tone"

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
You may also need to look at punctuation marks.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
yes that's the problem. I can't put a space either side when searching because you could have a sentence finishing:

"....... the desired tone."

Which does not have a space either side. I can't think of a straightforward way of doing it!

A computer always does what you tell it to, but rarely does what you want it to.....
 
[tt]dim s,t,rx
set rx=new regexp
with rx
.pattern="\btone\b"
.ignorecase=true
.global=true
end with
's being the pre-replaced string
t=rx.replace(s,"string-to-replace-tone-ignore-case")
[/tt]
 
That's it - a bit of fiddling and it worked. Thanks tsuji, I knew that regular expressions were handy but I never used them before! Have a star............



A computer always does what you tell it to, but rarely does what you want it to.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top