• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1943
  • Last Modified:

AddSlash / StripSlash equivalent for VB6 (escape characters in VB60 MySQL)

Hi Experts,

I tried to use a string to select/insert data to a My SQL table, but it give me errors on characters that needs an escape character. so inserting  aa\bb\cc'c must be aa\\bb\\cc\'c (took me some time to understand that :)
What is the fastest way to place these escape characters from VB60, without scanning my string char. by char.
And do I need to remove these characters after retreiving the data from MySQL?

Regards,
Murph
0
Murphey
Asked:
Murphey
  • 4
  • 3
  • 2
1 Solution
 
GrahamSkanRetiredCommented:
strText = Replace(strText, "\", "\\")
0
 
GrahamSkanRetiredCommented:
To turn it back again, use
strText = Replace(strText, "\\", "\")

0
 
Steve BinkCommented:
GrahamSkan has the right idea, but you need to expand the replacement to more than just the slash character.  Take a look here for what characters are escaped with PHP's mysql-specific function:

http://www.php.net/manual/en/function.mysql-real-escape-string.php
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
MurpheyApplication ConsultantAuthor Commented:
Hi routinet, GrahamSkan,

And yes I know that  Replace(strText, "\", "\\")  will do the trick
but what about \'  and \&   and \+ and \_ ? (and maybe more)
do I have to d a replace for every token?

Yes I know how to do it in PHP, i need it in VB and I don't think this link will give me more info, but I will read it again when I'm home.

Thanks,
Murph


0
 
Steve BinkCommented:
The link I posted will give you the characters you need to worry about.

As far as replacement, yes, I believe you'll have to execute one Replace() call for each character.  It's been a long time since I worked with VB6, but I don't recall a way to do multiple replacements with it.  I suppose the easiest way would be to generate a function to escape everything, and call that.  Inside that function, have a constant array of things to look for, and things to replace them with.  Iterate through the array and execute Replace() once for each set of elements.
0
 
GrahamSkanRetiredCommented:
In principle, yes.
I don't know how many special character there are, but a succession of replacements would not be too unwieldy. Of course the \ replacement would have to be done first.

strText = Replace(strText, "\", "\\")
strText = Replace(strText, "'", "\'")
strText = Replace(strText, "&", "\&")
strText = Replace(strText, "+", "\+")



0
 
MurpheyApplication ConsultantAuthor Commented:
Hi GrahamSkan,

If possible I like to do it in 1 "replace",
The problem is here, that it's a program that runs for aprox. 40 minutes I brought that back to 25.
it analyzes 18000 objects and 18000 *  5 is probably 18000 * 4 times to much :)

Regards,
Murph
0
 
MurpheyApplication ConsultantAuthor Commented:
Hi Routinet,

"Iterate through the array and execute Replace() once for each set of elements."

in that case I'll better use multiple replaces because iterations and substringing or character array's cost loads of milliseconds :) :) :)

Murph
0
 
MurpheyApplication ConsultantAuthor Commented:
Thanks GrahamSkan.
it works, but not the way I like :(
but it only extend the time with ca. 40 seconds :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now