Results 1 to 5 of 5

Thread: Remove() Function?

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    54

    Remove() Function?

    Hi guys,

    I'm just wondering if anybody has written a Remove Function. I'm getting a bit sick of having to use Mid() all the time, and I believe it's slowing down my program a little.. unfortunately, I don't have the know-how yet to write myown remove function..

    Thanks,

    P.S - What I basically am looking for is something that would work similiar to this:

    str = "bah!"
    newstr = Remove(str,"b")

    Which would just return 'ah!'

    Thanks heaps everybody

  2. #2
    Addicted Member
    Join Date
    Jul 2002
    Posts
    234
    You could use Replace to do the same thing as your example here:

    VB Code:
    1. test = "bah!"
    2. test = Replace(test, "b", "")
    3. msgbox test

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    54
    That's what I was originally doing, but I came across a problem..

    What if the string was something like "baboon"? It'd change it to "aoon" instead of just "aboon".. any ideas?

    Thanks

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Well , how about using Left( ) Function ?

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Or do you just want to strip out the first occurence of a character?
    VB Code:
    1. Private Function Remove(ByVal RemoveFrom As String, ByVal ToRemove As String, _
    2.                         Optional Count As Integer = 1) As String
    3.  
    4.     If Not (Count >= 1) Then Err.Raise 5
    5.  
    6.     Remove = Replace(RemoveFrom, ToRemove, "", Count:=Count)
    7.  
    8. End Function
    9.  
    10. Private Sub Command1_Click()
    11.     MsgBox Remove("baboon", "b")
    12. End Sub

    I believe that is case sensitive, but it can easily be changed not to be.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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