|
-
Nov 15th, 2005, 01:51 AM
#1
Thread Starter
Hyperactive Member
[resolved]replacing words?
i have a string called strOne = "hello and goodbye andONe and Hey"
i would like to replace all the "and" words with "hi"
so the new string would be strOne = "hello hi goodbye andONe hi Hey"
i tried strOne = replace(strOne, "and", "hi") but it replaces all and anything that contains "and" which is not what i want. What i want is to replace the word "and". how would i do that?
Last edited by Whatupdoc; Nov 15th, 2005 at 07:39 PM.
-
Nov 15th, 2005, 02:35 AM
#2
Re: replacing words?
Try strOne = Replace(strOne," and "," hi ")
-
Nov 15th, 2005, 02:54 AM
#3
Thread Starter
Hyperactive Member
Re: replacing words?
oh yea, i never thought of that. thanks alot
-
Nov 15th, 2005, 03:04 AM
#4
Re: replacing words?
Doing that way will not change strings that starts or ends with the word "and" since they only have a space before or after the word and not at both ends. So maybe you should add a space at the start and at the end of the string before you do the replacement. You should in that case also remove the spaces afterwards.
VB Code:
strOne = Replace(" " & strOne & " ", " and ", " hi ")
strOne = Mid$(strOne, 2, Len(strOne) - 2)
-
Nov 15th, 2005, 07:21 PM
#5
Thread Starter
Hyperactive Member
Re: replacing words?
i have to switch from textbox to richtextbox because textbox cannot hold all the data that i want. I found this code somewhere on this forum:
RichTextBox1.Text = RichTextBox1.Text.Replace("hello", "by")
but it doesnt work
-
Nov 15th, 2005, 07:31 PM
#6
Re: replacing words?
VB Code:
Do While RichTextBox1.Find("hello", , , rtfWholeWord) > -1
RichTextBox.SelText = "bye"
Loop
-
Nov 15th, 2005, 07:38 PM
#7
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|