Results 1 to 5 of 5

Thread: string manipulation

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Connecticut
    Posts
    98
    I have a string that I would like to remove a piece of. I know the Mid function will extract a section out of a string, but I want to do the opposite. I'd like to remove part of a string and keep the rest. Is there a function that does this?

    Example:
    string="aaabbbcccdddeee"
    and I want to remove "bbb"
    and end up with:
    string="aaacccdddeee"

    Or does this have to be done manually using Len, InStr, etc?

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Here's two ways ...

    Code:
        x = "aaabbbcccdddeee"
        x = Replace(x, "bbb", "")
        Debug.Print x
        
        x = "aaabbbcccdddeee"
        x = Left(x, 3) & Mid(x, 7)
        Debug.Print x
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Lively Member
    Join Date
    Feb 2001
    Posts
    78
    Nevermind, didn't know there was "Replace"...

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    In theory you could use this approach too :

    Code:
        x = "aaabbbcccdddeee"
        Mid(x, 4, 3) = ""
        Debug.Print x
    But the mid statement doesnt like replacing things with 0 length strings. So if you wanted to replace it will something else ...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Connecticut
    Posts
    98

    =)

    That was enough to get done what I needed to.

    Thanks!
    ~Piz

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