Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Escaping special characters

Status
Not open for further replies.

onedizzydevil

Programmer
Mar 24, 2001
103
US
Hello Folks:

I have a problem that needs a solution, I am using ASP, VBScript, JavaScript and a Microsoft Access database on the this project.

I use text boxes and text areas on some data entry pages in this application and I receive errors when I attempt to do most things with the data including INSERT INTO the database; some of the special characters such as a carraige return (ASC(13)), a line feed (ASC(10)), an apostrophe character (ASC(39)), and the parentheses characters (ASC(40), ASC(41)).

The characters need to be there when the data is returned back to the user(s) on a web page or when edited in another form, therefore what ever I do must be able to be undone or reversed during a display.

Thank you in advance for your help, I do greatly appreciate it.


Wayne Sellars
 
Hello, I had trouble with this yesterday as well, here is the function someone gave me. Run this and store the NewString into your database.

****
NewString = Replace(OriginalString,"'","''")
****

Hope this helps
 
If you're gonna use the stored data on other web pages later, another solution is to "webify" them.

Code:
  myString = Replace(myString, """",""")
  myString = Replace(myString, "'", "'")

In that case, you might also want to add some
extra code to avoid some simple web page "hacks".
Code:
  myString = Replace(myString, &quot;<&quot;, &quot;&lt;&quot;)
  myString = Replace(myString, &quot;>&quot;, &quot;&gt;&quot;)

Palooka
 
Well, it seems the forum translated my code, even though I tried to avoid it. Very well... :)

Here they are again (remove the underscore) :
Code:
  myString = Replace(myString, &quot;&quot;&quot;&quot;, &quot;&_quot;&quot;)
  myString = Replace(myString,  &quot;'&quot;, &quot;&_#39;&quot;)
  myString = Replace(myString,  &quot;<&quot;, &quot;&_lt;&quot;)
  myString = Replace(myString,  &quot;>&quot;, &quot;&_gt;&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top