Advertisement

07.08.2008 at 07:35PM PDT, ID: 23548945
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

VB.NET 2005 Replace function not replacing Single Quote with BackSlash Single Quote

Asked by TedPalmer in Microsoft Visual Basic.Net

Tags: , , ,

My OS is Windows XP SP2 and my IDE is Visual Studio 2005. My program is written in VB.NET 2005. My RDBMS is MySQL version 5.0.45

Context: I have been working on this program for about 2 years now so I have lots of experience writing dynamic SQL that successfully interfaces with MySQL. The commented out code
'Return Chr(39) & Input.Replace("'"c, "\'") & Chr(39)
was written about one year 5 months ago and was working just fine in VB.NET 2003. I upgraded to VB.NET 2005 last January and have not rigerously tested this function, FixSingleQuote1, since then. It just seemed to work when I used it till today when I happen to stress it a little harder. The commented line of code was provided to me by another EE Expert and was the only line of code in the whole function till today. He said it used Regular Expression syntax which I was not familiar with at the time, but I made up some rigorious test cases and it worked without any problems. I took him at his word and I still do. I confess I never really understood how it worked, but since it did, I didn't question it. I just used it and was glad for a freebee that solved a problem for which I had a much less elegent solution that only worked when there was just one single quote in the input text string.

Today I copied and pasted from a webpage some biographical data on one of the US Supreme Court Justices that I was using as test data. It had a few single quotes in it that caused MySQL to return an error message saying my SQL syntax had an error in it. Maybe this was the first time since converting to VB.NET 2005 that I have actually tried to enter any text that had single quotes in it.

I am just trying to convert all occurances of a string of length one from a single quote character to a two character string of backslash single quote and return the whole string delimited by single quote characters, The help gives the following example:

Dim TestString As String = "Shopping List"
' Returns "Shipping List".
Dim aString As String = Replace(TestString, "o", "i")

This looks like a very simple function to use. In debug I can step through the code and see the single quote characters in my Input string. I can execute the assignment statement and look at the Output string. Nothing has changed. The single quotes are still there without the backslash character preceding them. Char(92) = ASCII backslash character and Char(39) is the single quote character.

This is so simple I can't see where I am doing anything wrong. If I am wrong, I'm not too proud to admit it. If this is a known bug in VB.NET 2005, is there a commonly used work around?

Thank you,
Ted Palmer
www.tedpalmer.comStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Public Function FixSingleQuote1(ByVal Input As String) As String
        Dim oldSingleQuote As String = "'"
        'Dim newSingleQuote As String = "\'"
        Dim newSingleQuote As String = Chr(92) & "'"
        Dim Output As String = ""
        'Return Chr(39) & Input.Replace("'"c, "\'") & Chr(39)
        'Return Chr(39) & Input.Replace("'"c, "''") & Chr(39)
        Output = Chr(39) & Replace(Input, oldSingleQuote,newSingleQuote) & Chr(39) '<-- As of 2008-07-08 by Ted Palmer
        Return Output '<-- As of 2008-07-08 by Ted Palmer
    End Function 'FixSingleQuote1
 
Loading Advertisement...
 
[+][-]07.08.2008 at 08:59PM PDT, ID: 21960502

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 06:15AM PDT, ID: 21963197

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 06:30AM PDT, ID: 21963330

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 08:24AM PDT, ID: 21964676

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 10:29AM PDT, ID: 21966134

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 11:18AM PDT, ID: 21966625

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 01:05PM PDT, ID: 21967749

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 08:49AM PDT, ID: 21974606

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 09:23AM PDT, ID: 21974997

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 09:30AM PDT, ID: 21975081

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 11:24AM PDT, ID: 21976110

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 11:49AM PDT, ID: 21976324

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 01:32PM PDT, ID: 21977110

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 02:54PM PDT, ID: 21977721

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: Microsoft, Visual Basic 2005 (VS2005), 2005, OS = Windows XP SP2; RDBMS = MySQL
Sign Up Now!
Solution Provided By: planocz
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.10.2008 at 03:54PM PDT, ID: 21978073

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.11.2008 at 07:25AM PDT, ID: 21982656

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.11.2008 at 10:30AM PDT, ID: 21984330

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 09:50AM PDT, ID: 21999757

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 11:06AM PDT, ID: 22000462

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 11:11AM PDT, ID: 22000506

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628