954,582 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How Remove unwanted characters from a string ?

Hi All,

I want to ask how to remove unwanted character from string??
Can provide an example?


Dim A As String
A = "@AA@BB@CC@DD"
If i want to remove @BB what method i should use?
First i try to use instr to detect where the @BB but how to do next?
Can help me and provide an example thank you....


Thanks

gingank
Junior Poster
109 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Look up the functions RIGHT() LEFT() MID() and LEN().

WaltP
Posting Sage w/ dash of thyme
Moderator
10,507 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

thats easy. Use Replace function.

Dim A as string 
A = Replace("@AA@BB@CC@DD", "@BB", vbNullString)

it will return @AA@CC@DD

Hopes this solves your problem.

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

thats easy. Use Replace function.

Dim A as string 
A = Replace("@AA@BB@CC@DD", "@BB", vbNullString)

it will return @AA@CC@DD

Hopes this solves your problem.


Thank Jahai it help a lot
If i want to remove multiple character just like this how should i do can give example:-
Dim A As String

'' Remove multiple character
A = "@AA@BB@CC@DD@EE@FF@GG@HH@AB"

'END Result
A = "@AA@GG@HH@"
So what method should i use next

gingank
Junior Poster
109 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Just repeat the Replace Function.

Dim A as string, B as string 
A = "@AA@BB@CC@DD@EE@FF@GG@HH@AB"
A = Replace(A, "@BB", vbNullString)
'etc
jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

Just repeat the Replace Function.

Dim A as string, B as string 
A = "@AA@BB@CC@DD@EE@FF@GG@HH@AB"
A = Replace(A, "@BB", vbNullString)
'etc


thanks for the information

gingank
Junior Poster
109 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Your welcome! :D now mark this thread as solve...

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 
Your welcome! :D now mark this thread as solve...


I still have a few question to ask before i mark this as solve

Dim A As String

A = "@AA@BB2@CC1@DD3@EE4"

''If detected CC , DD or EE5 then replace

If i do this

A = Replace(A,"@CC",vbnullstring)
A = Replace(A,"@EE4",vbnullstring)

The result will become like this
A = "@AA@BB21@DD3"

But i want to remove @CC only & not the @CC1, what the method i should use?
I want the output like this

A = "@AA@BB2@CC1@DD3"

gingank
Junior Poster
109 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

You can use loop then use the Mid function and Iterate through the whole string.

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 
You can use loop then use the Mid function and Iterate through the whole string.

Can you provide me an example of the coding how to do it?
I not really understand what you mean here...
Please help me....

gingank
Junior Poster
109 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

How about showing your effort first?

You can check out this code snippet of mine to see how I manipulate the strings.

Here

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

Nice Jhai. The poster needs to understand that we are not here to do THEIR homework for them. Show some effort, play with the samples given and find the solution. Do you really expect Jhai to do ALL of the coding and solution for you?

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

:D my given samples should work with your needs so you just need to analyze and understand it.

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You