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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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

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 TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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

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.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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...
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
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.
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.