Remove special characters

businesshippieRH

Registered User.
Local time
Today, 04:20
Joined
Aug 8, 2014
Messages
60
I've come across a slight problem and was wondering what approaches others have used to solve it...

I have a Memo field that is used to be a description of a document. I don't know what the user will put in (could be anything), but it is eventually passed in a string to a query, etc.

The problem: I discovered during testing that if an apostrophe is entered (Ex: This document explains how to deal with Joe's pleasant disposition.), it breaks my code. I then realized that all reserved words and characters would cause this problem.:banghead:

I can get around this one just by using Replace(str, "'", "''"). However, I know there are others that will cause problems, and I don't want to end up with a string of replace statements just to fix them. Any advice?

Thanks in advance!
 
I don't want to end up with a string of replace statements just to fix them.

Create a function. Make an array of the characters/words to change and an array of what to replace them with. Loop through those arrays and execute a Replace on the string each time.

Then when you find a new word/character, add it to the array along with a replacement.
 
Also: I got to thinking... is there anything else that would break code other than ' and " ? If not, I may just stick with the simple replace. Otherwise everything inside my string should be caught in between quotes for the string, right?...

Ex: "blah blah * blah". = blah blah * blah
Whereas: "blah blah ' blah" = blah blah And an error...
 

Users who are viewing this thread

Back
Top Bottom