473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Testing for double apostrophe in a string

A client needs a routine to alert him as to which memo records in an
Access-2000 database have had double apostrophes inserted in the text.
These are stopping a Java mouseover from executing.

Normally, while cycling through the recordset, I would use the InStr
function to test for a positive result indicating and embedded text.

ie. If InStr(rstemp("Keywords"),"searched") > 0 Then

would give a true for all <keywords> fields that contained the text
< searched >

But what do you do if you're looking for a double apostrophe itself.?

To specify the string you are searching for you can't use a single
apostrophe to deliniate the string, such as ' " ' and of course
using " " " won't work either.

Is there a character expression maybe that one could use instead.?

Or can someone perhaps suggest shattering my paradigm by using
something other than an If test on a function. Or maybe a different
function.?

thanks ( in anticipation )

. les .

Jul 22 '05 #1
5 1994
How about passing it through a function to replace the ' with \'?

<%
sValue = "I'm a string"
Function jsEncode(s)
jsEncode = Replace(s, "'", "\'")
End Function
%>

<button onclick="alert('<%=jsEncode(sValue)%>');">Click me</button>
Ray at work

"Les Juby" <le*****@anti-spam.iafrica.com> wrote in message
news:42**************@news.telkomsa.net...
A client needs a routine to alert him as to which memo records in an
Access-2000 database have had double apostrophes inserted in the text.
These are stopping a Java mouseover from executing.

Normally, while cycling through the recordset, I would use the InStr
function to test for a positive result indicating and embedded text.

ie. If InStr(rstemp("Keywords"),"searched") > 0 Then

would give a true for all <keywords> fields that contained the text
< searched >

But what do you do if you're looking for a double apostrophe itself.?

To specify the string you are searching for you can't use a single
apostrophe to deliniate the string, such as ' " ' and of course
using " " " won't work either.

Is there a character expression maybe that one could use instead.?

Or can someone perhaps suggest shattering my paradigm by using
something other than an If test on a function. Or maybe a different
function.?

thanks ( in anticipation )

. les .

Jul 22 '05 #2
here is a function I wrote a couple years back.
(probably can be simplified/improved but works fine)

I use the javascript part of it just for the purpose you are talking about

Function FixStr(StrToFix,FixHow)
' This function prepares a string for saving in the database
' And also can prepare a string for editing in a text box
' The reason we need to do this is to stop users from entering HTML or
Javascript
' And also to make sure line breaks get converted to <br> tags

If Not IsNull(StrToFix) and StrToFix <> "" Then

If FixHow = "PrepareForSave" then
StrToFix = replace(StrToFix,"<","&lt;")
StrToFix = replace(StrToFix,">","&gt;")
StrToFix = Replace(StrToFix,vbCr,"<br>")
ElseIf FixHow = "PrepareForTextBox" then
StrToFix = replace(StrToFix,"&lt;","<")
StrToFix = replace(StrToFix,"&gt;",">")
StrToFix = Replace(StrToFix,"<br>",vbCr)
ElseIf FixHow = "PrepareForJavaScript" then
StrToFix = replace(StrToFix,"'","\'")
StrToFix = replace(StrToFix,"""","\'\'")
StrToFix = Replace(StrToFix,vbCrLf,"<br>")
StrToFix = Replace(StrToFix,vbLf,"<br>")
StrToFix = Replace(StrToFix,vbNewLine,"<br>")
End If

End If

FixStr = StrToFix
End function
and you use it like this

FixStr(YourVariable,"PrepareForJavaScript")

I got the idea from an article at
www.powerasp.com


"Les Juby" <le*****@anti-spam.iafrica.com> wrote in message
news:42**************@news.telkomsa.net...
A client needs a routine to alert him as to which memo records in an
Access-2000 database have had double apostrophes inserted in the text.
These are stopping a Java mouseover from executing.

Normally, while cycling through the recordset, I would use the InStr
function to test for a positive result indicating and embedded text.

ie. If InStr(rstemp("Keywords"),"searched") > 0 Then

would give a true for all <keywords> fields that contained the text
< searched >

But what do you do if you're looking for a double apostrophe itself.?

To specify the string you are searching for you can't use a single
apostrophe to deliniate the string, such as ' " ' and of course
using " " " won't work either.

Is there a character expression maybe that one could use instead.?

Or can someone perhaps suggest shattering my paradigm by using
something other than an If test on a function. Or maybe a different
function.?

thanks ( in anticipation )

. les .

Jul 22 '05 #3
you have to test for those line breaks too and convert them to "<br>"'s
because if their are any it messes up your javascript as well

probably overkill the way I am testing for line breaks but like I said it
works well under all scenarios I have come up with so far

so like Grandma used to say "Fuck it !"
"Kyle Peterson" <kp*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
here is a function I wrote a couple years back.
(probably can be simplified/improved but works fine)

I use the javascript part of it just for the purpose you are talking about

Function FixStr(StrToFix,FixHow)
' This function prepares a string for saving in the database
' And also can prepare a string for editing in a text box
' The reason we need to do this is to stop users from entering HTML or
Javascript
' And also to make sure line breaks get converted to <br> tags

If Not IsNull(StrToFix) and StrToFix <> "" Then

If FixHow = "PrepareForSave" then
StrToFix = replace(StrToFix,"<","&lt;")
StrToFix = replace(StrToFix,">","&gt;")
StrToFix = Replace(StrToFix,vbCr,"<br>")
ElseIf FixHow = "PrepareForTextBox" then
StrToFix = replace(StrToFix,"&lt;","<")
StrToFix = replace(StrToFix,"&gt;",">")
StrToFix = Replace(StrToFix,"<br>",vbCr)
ElseIf FixHow = "PrepareForJavaScript" then
StrToFix = replace(StrToFix,"'","\'")
StrToFix = replace(StrToFix,"""","\'\'")
StrToFix = Replace(StrToFix,vbCrLf,"<br>")
StrToFix = Replace(StrToFix,vbLf,"<br>")
StrToFix = Replace(StrToFix,vbNewLine,"<br>")
End If

End If

FixStr = StrToFix
End function
and you use it like this

FixStr(YourVariable,"PrepareForJavaScript")

I got the idea from an article at
www.powerasp.com


"Les Juby" <le*****@anti-spam.iafrica.com> wrote in message
news:42**************@news.telkomsa.net...
A client needs a routine to alert him as to which memo records in an
Access-2000 database have had double apostrophes inserted in the text.
These are stopping a Java mouseover from executing.

Normally, while cycling through the recordset, I would use the InStr
function to test for a positive result indicating and embedded text.

ie. If InStr(rstemp("Keywords"),"searched") > 0 Then

would give a true for all <keywords> fields that contained the text
< searched >

But what do you do if you're looking for a double apostrophe itself.?

To specify the string you are searching for you can't use a single
apostrophe to deliniate the string, such as ' " ' and of course
using " " " won't work either.

Is there a character expression maybe that one could use instead.?

Or can someone perhaps suggest shattering my paradigm by using
something other than an If test on a function. Or maybe a different
function.?

thanks ( in anticipation )

. les .


Jul 22 '05 #4
you have to test for those line breaks too and convert them to "<br>"'s
because if their are any it messes up your javascript as well

probably overkill the way I am testing for line breaks but like I said it
works well under all scenarios I have come up with so far

so like Grandma used to say "F@#! it !"
"Kyle Peterson" <kp*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
here is a function I wrote a couple years back.
(probably can be simplified/improved but works fine)

I use the javascript part of it just for the purpose you are talking about

Function FixStr(StrToFix,FixHow)
' This function prepares a string for saving in the database
' And also can prepare a string for editing in a text box
' The reason we need to do this is to stop users from entering HTML or
Javascript
' And also to make sure line breaks get converted to <br> tags

If Not IsNull(StrToFix) and StrToFix <> "" Then

If FixHow = "PrepareForSave" then
StrToFix = replace(StrToFix,"<","&lt;")
StrToFix = replace(StrToFix,">","&gt;")
StrToFix = Replace(StrToFix,vbCr,"<br>")
ElseIf FixHow = "PrepareForTextBox" then
StrToFix = replace(StrToFix,"&lt;","<")
StrToFix = replace(StrToFix,"&gt;",">")
StrToFix = Replace(StrToFix,"<br>",vbCr)
ElseIf FixHow = "PrepareForJavaScript" then
StrToFix = replace(StrToFix,"'","\'")
StrToFix = replace(StrToFix,"""","\'\'")
StrToFix = Replace(StrToFix,vbCrLf,"<br>")
StrToFix = Replace(StrToFix,vbLf,"<br>")
StrToFix = Replace(StrToFix,vbNewLine,"<br>")
End If

End If

FixStr = StrToFix
End function
and you use it like this

FixStr(YourVariable,"PrepareForJavaScript")

I got the idea from an article at
www.powerasp.com


"Les Juby" <le*****@anti-spam.iafrica.com> wrote in message
news:42**************@news.telkomsa.net...
A client needs a routine to alert him as to which memo records in an
Access-2000 database have had double apostrophes inserted in the text.
These are stopping a Java mouseover from executing.

Normally, while cycling through the recordset, I would use the InStr
function to test for a positive result indicating and embedded text.

ie. If InStr(rstemp("Keywords"),"searched") > 0 Then

would give a true for all <keywords> fields that contained the text
< searched >

But what do you do if you're looking for a double apostrophe itself.?

To specify the string you are searching for you can't use a single
apostrophe to deliniate the string, such as ' " ' and of course
using " " " won't work either.

Is there a character expression maybe that one could use instead.?

Or can someone perhaps suggest shattering my paradigm by using
something other than an If test on a function. Or maybe a different
function.?

thanks ( in anticipation )

. les .


Jul 22 '05 #5
"Les Juby" <le*****@anti-spam.iafrica.com> wrote in message
news:42**************@news.telkomsa.net...
A client needs a routine to alert him as to which memo records in an
Access-2000 database have had double apostrophes inserted in the text.
These are stopping a Java mouseover from executing.

Normally, while cycling through the recordset, I would use the InStr
function to test for a positive result indicating and embedded text.

ie. If InStr(rstemp("Keywords"),"searched") > 0 Then

would give a true for all <keywords> fields that contained the text
< searched >

But what do you do if you're looking for a double apostrophe itself.?

To specify the string you are searching for you can't use a single
apostrophe to deliniate the string, such as ' " ' and of course
using " " " won't work either.

Is there a character expression maybe that one could use instead.?

Or can someone perhaps suggest shattering my paradigm by using
something other than an If test on a function. Or maybe a different
function.?

thanks ( in anticipation )

. les .


If InStr(rstemp("Keywords"),Chr(34)) > 0 Then ...

OR

If InStr(rstemp("Keywords"),"""") > 0 Then ...

Here's an article that discusses embedded quotes:
http://aspfaq.com/show.asp?id=2065
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Bird | last post by:
I am attempting to build a command string to update a field in a dataset. the command string looks like this: Dim cmdString As String = "Update set lName = '" & clName.Trim & "', fName = '" &...
13
by: Joey Martin | last post by:
I'm sure this has to be a simple fix. I just cannot figure it out. To resolve the typical apostrope issue, I have the acarriername = Replace(txtcarriername.text, "'", "''") My problem is that...
4
by: (PeteCresswell) | last post by:
Is his just a flat-out "No-No" or is there some workaround when it comes time for SQL searches and DAO.FindFirsts against fields containing same? I can see maybe wrapping the value searched for...
3
by: wrytat | last post by:
How to you print a double apostrophe in asp.net using vb? meaning for e.g. I want to write ", So I do a Response.Write(""") Something like that, but the mentioned is wrong. Thank you in advance
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
9
by: Huy | last post by:
I've been unable to find information clarifying this but. What is the difference between 'somestring' and "somestring"? When I use type() it still reports as string. If there is a difference...
1
by: MRW | last post by:
I'm working with an Access 2002 database. Whenever I entered information from a from into the database, I replace every apostrophe with a double apostrophe as everybody has suggested. However, at...
1
by: karen987 | last post by:
I have an ASP news page to which you can add comments. The comments open up in a new window, and users can click reply to reply to them after which they are taken to the parent page which has a...
2
by: Earl | last post by:
Anyone know why the RowFilter has to be double-escaped? Anticipating names with apostrophes, a single escape does not provide the proper name to filter on. For example, this would cause an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.