Searching and replacing words from a text box

If i have a textbox with some text in it, how cand i search and replace a word let's say "word" with some other words "word number 2".
macailaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bobbit31Commented:
textbox1.text = Replace(textbox1.text, "word", "word number 2")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kidgenius2002Commented:
if you know what the word is, and it's length, you could do something like the following

x=1
'z is length of "word", in this case 4'
z= 4
do until mid(textbox1.text,x,z) = "word"
     x=1+x
     loop
textbox1.text = left(textbox1.text,x) & "word number 2" & right(textbox1.ext,x+z)
0
DocMCommented:
Or the old method:

a = "1234 word 5678"
 strToSearch = "word"
 strReplaceBy = "word number 2"
 start = 1
While InStr(start, a, strToSearch)
 a = Mid(a, 1, InStr(start, a, strToSearch) - 1) & strReplaceBy & Mid(a, InStr(start, a, strToSearch) + Len(strToSearch))
 start = start + Len(strReplaceBy)
Wend
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JacamarCommented:
Here you go.

Private Sub Command1_Click()
Text1.Text = Replace(Text1.Text, "word", _
                "word number 2")

Text1.Text = Replace(Text1.Text, "word", _
                "word")

Text1.SelStart = Len(Text1.Text)

End Sub
0
aelatikCommented:
OK, i think im missing something here ! What is wrong with bobbit31's post. It's the best answer that fits this question, why make it so complex ?
0
bobbit31Commented:
lol, my thoughts exactly ;)
0
DocMCommented:
Some like it complex.
And it is only with an educational purpose.
0
macailaAuthor Commented:
I'll accept one answer as soon as I get VB6 I use VB4 so I get error messages.
0
macailaAuthor Commented:
Well bobbit31 was the first person who answered me and i try not to make my programs complex because that would mean they wouldn't run on older computers...
0
bobbit31Commented:
so why the 'B' grade?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.