Solved

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

Posted on 2011-02-24
6
524 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

948 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now