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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing apostrophe's in strings

Status
Not open for further replies.

bigben

Programmer
Oct 8, 2001
25
RO
I'm getting an error on an ASP page. I have a text box that users can enter information into and then submit. When they submit it writes that information to a database. However if the user includes any apostrophes in their text it throws up an error.

Does anyone know of an answer to this one. Maybe replacing the apostrophes with an ASCII code before submitting? But I don't know the correct way to phrase this.

I checked keyword before starting this thread but could not find anything.

I would be grateful for any help.

Many thanks
 
you could try replacing them with spaces like this
Sub Rid()
Dim TheForm, MyVar
TheForm = "!!I get rid of the ! in this string!!!"
alert TheForm
'Start by trimming leading/trailing spaces

'Now, replace spaces...
Do While InStr(1, TheForm, "!")
TheForm = Replace(TheForm, "!", " ")
Loop
MyVar = MsgBox ("All Gone" & TheForm)

End Sub [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Thank you for your reply. I eventually managed to solve it using the following code where "Ro" is the variable holding the string:

Ro = Replace(Ro,"'","' & Chr(39) & '",1,-1,1)

Which seems to do the trick

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top