Solved

How to remove quotes from the beginning and end of the string

Posted on 2011-02-24
6
529 Views
Last Modified: 2012-05-11
I am not sure how to find if there is a quote (") at the beginning or the end of the string, if they are present, I would like to remove it.

I am using a VB
0
Comment
Question by:tommym121
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 34976222
Does it have to be just at the beginning or end?  If not, try this to get rid of all double-quotes (") in the string:

mystring = mystring.Replace("""",string.Empty)

Open in new window

0
 
LVL 14

Expert Comment

by:quizwedge
ID: 34976231
If you just want to get rid of the beginning and end, the following will work
       
        If mystr.StartsWith("""") Then
            mystr = mystr.Substring(1)
        End If

        If mystr.EndsWith("""") Then
            mystr = mystr.Substring(0, mystr.Length - 1)
        End If

Open in new window

0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34976234
These two lines should trim quotes from start and end of string only:

mystring = mystring.TrimStart("""");
mystring = mystring.TrimEnd("""");

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tommym121
ID: 34976256
I am using VBA.
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34976270
tommym121, all these examples, including quizwedge's, are meant to be for VBA.   I guess I shouldn't have used semicolons on my second example.

mystring = mystring.TrimStart("""")
mystring = mystring.TrimEnd("""")

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 34976553
If you want VBA then don't add VB.Net as a zone...

Try something like:
Dim value As String
    value = Chr(34) & "blah" & Chr(34)
    
    If Left(value, 1) = Chr(34) Then
        value = Mid(value, 2)
    End If
    If Right(value, 1) = Chr(34) Then
        value = Left(value, Len(value) - 1)
    End If

Open in new window

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question