[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1814
  • 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
theo kouwenhoven
Asked:
theo kouwenhoven
  • 4
  • 3
  • 2
1 Solution
 
GrahamSkanCommented:
strText = Replace(strText, "\", "\\")
0
 
GrahamSkanCommented:
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
theo kouwenhovenAuthor 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
 
GrahamSkanCommented:
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
 
theo kouwenhovenAuthor 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
 
theo kouwenhovenAuthor 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
 
theo kouwenhovenAuthor Commented:
Thanks GrahamSkan.
it works, but not the way I like :(
but it only extend the time with ca. 40 seconds :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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