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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A better replace function 1

Status
Not open for further replies.

perplexd

Programmer
May 9, 2002
154
US
I am using a replace function to correctly capitalise a word. ie I want the word to be "PDXtra", which means that all versions: "pdxtra", "pdextra" and "pd extra" must be changed, no matter where in the word there are capitals.

Basically I need a replace function which looks at the letters, but not the case. If a word matches "pdextra" or "pdxtra" then it must be changed to "PDXtra".

Is there such a function, or must I go about writing it myself?

Many thanks for any replies!
 

Hi, perplexed

Have you tried the vbBinaryCompare option of the replace function - that should do it... Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
If you want to achieve this

>'the word to be "PDXtra", which means that all versions: "pdxtra", "pdextra" and "pd extra" must be changed, no matter where in the word there are capitals.'

you will need to strip out the space before doing the compare
Let me know if this helps

Check out FAQ222-2244
'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 

Johnwm is right about the space that has to be stripped.

I was a little fast on the keyboard, you should of course use vbTextCompare to replace independant of case...
(vbBinaryCompare is the default comparison method, which is case sensitive). X-)
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Cheers guys. The space is not an issue though:
NewText = Replace(NewText, "pd extra", "PDXtra", , , vbTextCompare)

This works with the space...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top