How to remove a certain character from a string

If I have a VB.net string, how do I remove a certain character from the string for example the character I need to remove is a double quote. So for example If I have a VB.net string like :  """This Is The First Day""". I want to remove all of the double quotes so that it is now just :  This is The First Day
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Farzad AkbarnejadDeveloperCommented:
Hello,
Here is a sample code to represent your solution:
        Dim srcStr As String
        Dim desStr As String

        srcStr = """This Is The First Day"""
        MessageBox.Show("Source = " + srcStr)

        desStr = srcStr.Replace("""", "")
        MessageBox.Show("Dest. = " + desStr)

Open in new window

-FA
2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can also use Chr(34) to get a double quote.  My brain likes that better...just a matter of preference though.

Here's Farzad Akbarnejad's code, copied, using Chr(34) instead:
Dim srcStr As String
Dim desStr As String

srcStr = Chr(34) & "This Is The First Day" & Chr(34)
MessageBox.Show("Source = " + srcStr)

desStr = srcStr.Replace(Chr(34), "")
MessageBox.Show("Dest. = " + desStr)

Open in new window

0
brgdotnetcontractorAuthor Commented:
Hi. Neither of these will work if you have double quotes around the string. For example if I have a zip code
that looks like this:   ""80092"" the expert solutions above will change the string to "80092" but they will not totally remove all double quotes, which is what I wanted.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Neither of these will work if you have double quotes around the string. For example if I have a zip code that looks like this:   ""80092"" the expert solutions above will change the string to "80092" but they will not totally remove all double quotes

Um...no.  Here's a string with double-double quotes, which get removed:
Dim srcStr As String
Dim desStr As String

srcStr = Chr(34) & Chr(34) & "This Is The First Day" & Chr(34) & Chr(34)
Debug.Print("srcStr = " + srcStr)

desStr = srcStr.Replace(Chr(34), "")
Debug.Print("desStr = " + desStr)

Open in new window


Output:
srcStr = ""This Is The First Day""
desStr = This Is The First Day

Open in new window


Not sure what you're doing wrong...
0
Farzad AkbarnejadDeveloperCommented:
Hi,
If you trace your code and see the value in Watch Windows you will see double quotes around the string. You must check it by printing it in Debug window or on console.

-FA
0
brgdotnetcontractorAuthor Commented:
Thank you. The solution works perfectly. I was not able to log in for the last few days. My apologies for the delay.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.