Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-24
6
Medium Priority
?
548 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

885 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