Results 1 to 3 of 3

Thread: Searching a String for a word and Removing it???

  1. #1

    Thread Starter
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    If you are using vb6 you can use the Replace function. eg
    strWords = Replace(strWords, "basic", "")
    otherwise you need to use Instr in a loop to replace the word.

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Hi,

    I have a string called strWords and would like to click a button called cmdGo and have that button look inside the string for the word Basic and if it is found, Remove it. Will someBody please help?

    Thanks

  3. #3
    New Member
    Join Date
    Nov 1999
    Location
    Pittsburgh, PA, USA
    Posts
    6

    Post

    You could write your own function in a module such as:

    code
    -------------------------------------------
    Public Function RemoveStr(BaseStr As String, StrToRemove As String) As String
    Dim sTemp As String
    On Error GoTo ErrHandler

    'This ugly statement cuts the StrToRemove out of BaseStr
    sTemp = Left(BaseStr, InStr(BaseStr, StrToRemove) - 1) & _
    Mid(BaseStr, InStr(BaseStr, StrToRemove) + Len(StrToRemove), _
    Len(BaseStr) - InStr(BaseStr, StrToRemove) + Len(StrToRemove))
    RemoveStr = sTemp

    Exit Function

    ErrHandler:
    RemoveStr = ""
    Exit Function

    End Function

    -------------------------------------------

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