Results 1 to 7 of 7

Thread: [resolved]replacing words?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

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

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: replacing words?

    Try strOne = Replace(strOne," and "," hi ")

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: replacing words?

    oh yea, i never thought of that. thanks alot

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. strOne = Replace(" " & strOne & " ", " and ", " hi ")
    2. strOne = Mid$(strOne, 2, Len(strOne) - 2)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    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

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: replacing words?

    VB Code:
    1. Do While RichTextBox1.Find("hello", , , rtfWholeWord) > -1
    2.     RichTextBox.SelText = "bye"
    3. Loop

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: replacing words?

    nice thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width