Solved

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

Posted on 2011-02-24
6
523 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
Comment Utility
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
Comment Utility
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
Comment Utility
These two lines should trim quotes from start and end of string only:

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

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:tommym121
Comment Utility
I am using VBA.
0
 
LVL 16

Expert Comment

by:sjklein42
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

772 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

15 Experts available now in Live!

Get 1:1 Help Now