Solved

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

Posted on 2011-02-24
6
525 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Populate DataModel with DataTable 44 28
HTML - Color not displaying correctly in EMAIL. 6 37
Help with exporting to excel 4 27
.NET 2008 VB and C# 6 27
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

770 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