|
-
Apr 19th, 2001, 08:56 AM
#1
Thread Starter
Lively Member
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?
-
Apr 19th, 2001, 09:01 AM
#2
Retired VBF Adm1nistrator
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]
-
Apr 19th, 2001, 09:04 AM
#3
Lively Member
Nevermind, didn't know there was "Replace"...
-
Apr 19th, 2001, 09:09 AM
#4
Retired VBF Adm1nistrator
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]
-
Apr 19th, 2001, 09:17 AM
#5
Thread Starter
Lively Member
=)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|