Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Handling a literal string with a quote

Reply
Thread Tools

Handling a literal string with a quote

 
 
Toni
Guest
Posts: n/a
 
      08-27-2009
I have an application that inserts literal strings (raw strings) into an ASP template
that I can then work with. The problem is that I want to massage these strings in
ASP/VBScript and some of these strings contain quotes.

My ASP template can contain
myString = "$placeholder$"
where $placeholder$ is a raw string entered by the application.

This works fine if $placeholder$ doesn't contain any quotes, but if it does, the source
can for example look like this:
myString = "The Senator said "It's not my fault", then ran to his car"
which will, of course, generate an ASP error.

I have no control over the literal strings that may be entered, so I can't double-quote
them. How can I store these strings???

THANKS!!!


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      08-27-2009
Toni wrote on 27 aug 2009 in microsoft.public.inetserver.asp.general:

> I have an application that inserts literal strings (raw strings) into
> an ASP template that I can then work with. The problem is that I want
> to massage these strings in ASP/VBScript and some of these strings
> contain quotes.
>
> My ASP template can contain
> myString = "$placeholder$"
> where $placeholder$ is a raw string entered by the application.
>
> This works fine if $placeholder$ doesn't contain any quotes, but if it
> does, the source can for example look like this:
> myString = "The Senator said "It's not my fault", then ran to
> his car"
> which will, of course, generate an ASP error.
>
> I have no control over the literal strings that may be entered, so I
> can't double-quote them. How can I store these strings???


ASP/VBscript:

theString = replace(theString,"""","""""")

ASP/Jscript:

theString = theString.replace(/"/g,'""');


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
 
Toni
Guest
Posts: n/a
 
      08-27-2009
"Evertjan." wrote...
> Toni wrote on 27 aug 2009 in microsoft.public.inetserver.asp.general:
>
>> I have an application that inserts literal strings (raw strings) into
>> an ASP template that I can then work with. The problem is that I want
>> to massage these strings in ASP/VBScript and some of these strings
>> contain quotes.
>>
>> My ASP template can contain
>> myString = "$placeholder$"
>> where $placeholder$ is a raw string entered by the application.
>>
>> This works fine if $placeholder$ doesn't contain any quotes, but if it
>> does, the source can for example look like this:
>> myString = "The Senator said "It's not my fault", then ran to
>> his car"
>> which will, of course, generate an ASP error.
>>
>> I have no control over the literal strings that may be entered, so I
>> can't double-quote them. How can I store these strings???

>
> ASP/VBscript:
>
> theString = replace(theString,"""","""""")


NO, your suggestion generates an error, because if I insert this in the template:
theString = replace($placeholder$,"""","""""")

the template will generate this SOURCE CODE:
theString = replace(The Senator said "It's not my fault,"""","""""")
which will obviously crash.




 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      08-27-2009
Toni wrote:
> I have an application that inserts literal strings (raw strings) into
> an ASP template that I can then work with. The problem is that I want
> to massage these strings in ASP/VBScript and some of these strings
> contain quotes.
> My ASP template can contain
> myString = "$placeholder$"
> where $placeholder$ is a raw string entered by the application.


How? What does it do? Read the ASP file into memory and replace the
placeholders with text? Why can't it double the quotes as it does the
replacement?

>
> This works fine if $placeholder$ doesn't contain any quotes, but if
> it does, the source can for example look like this:
> myString = "The Senator said "It's not my fault", then ran to
> his car" which will, of course, generate an ASP error.
>
> I have no control over the literal strings that may be entered, so I
> can't double-quote them. How can I store these strings???
>

I don't understand where you are storing them.

I'm not clear about what's going on here. What is the application? Is it a
non-ASP application? Is it something whose source code you can modify?


--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Adrienne Boswell
Guest
Posts: n/a
 
      08-28-2009
Gazing into my crystal ball I observed "Toni" <(E-Mail Removed)> writing
in news:(E-Mail Removed):

> I have an application that inserts literal strings (raw strings) into
> an ASP template that I can then work with. The problem is that I want
> to massage these strings in ASP/VBScript and some of these strings
> contain quotes.
>
> My ASP template can contain
> myString = "$placeholder$"
> where $placeholder$ is a raw string entered by the application.
>
> This works fine if $placeholder$ doesn't contain any quotes, but if it
> does, the source can for example look like this:
> myString = "The Senator said "It's not my fault", then ran to
> his car"
> which will, of course, generate an ASP error.
>
> I have no control over the literal strings that may be entered, so I
> can't double-quote them. How can I store these strings???
>
> THANKS!!!
>
>


Since my crystal ball is in the shop, and you didn't tell us exactly
what the error was, I'm going to have to guess.

Is this error occuring when you are running a SQL query against that
data? If so, it is that single quote that is getting you into trouble.
What kind of database are you running the query against?

--
Adrienne Boswell at Home
Arbpen Web Site Design Services
http://www.cavalcade-of-coding.info
Please respond to the group so others can share

 
Reply With Quote
 
Toni
Guest
Posts: n/a
 
      08-28-2009
"Bob Barrows" wrote...
> Toni wrote:
>> I have an application that inserts literal strings (raw strings) into
>> an ASP template that I can then work with. The problem is that I want
>> to massage these strings in ASP/VBScript and some of these strings
>> contain quotes.
>> My ASP template can contain
>> myString = "$placeholder$"
>> where $placeholder$ is a raw string entered by the application.

>
> How? What does it do? Read the ASP file into memory and replace the placeholders with
> text? Why can't it double the quotes as it does the replacement?
>
>>
>> This works fine if $placeholder$ doesn't contain any quotes, but if
>> it does, the source can for example look like this:
>> myString = "The Senator said "It's not my fault", then ran to
>> his car" which will, of course, generate an ASP error.
>>
>> I have no control over the literal strings that may be entered, so I
>> can't double-quote them. How can I store these strings???
>>

> I don't understand where you are storing them.
>
> I'm not clear about what's going on here. What is the application? Is it a non-ASP
> application? Is it something whose source code you can modify?


It's a non-ASP application. It's a Perl application that when you publish the articles
generates static HTML files containing article text. I can set the static file to be a
..ASP file so that I can process the data.

The data is not stored in a database, it's stored in a huge text file that is a
proprietary format. When the article is published, it's published by taking the data
from the text file and generating the static file with the text.

Yeah, I know, no database and very old school. But there are over 300 articles stored in
this text file whose format I can't figure out and the vendor is out of business and
can't help decode it. One purpose of this project is to transfer it all in an MS SQL
database. The stumbling block is the text strings contain quotes.

A thought - because of the quotes, from what I've read here I think that these strings
can't be properly processed conventionally. I'm considering modifying the templates so
that instead of generating .ASP files, I'll generate simple .TXT files, then use
FileSystemObject to read in the text.




 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      08-28-2009
Toni wrote:
> It's a non-ASP application. It's a Perl application that when you
> publish the articles generates static HTML files containing article
> text. I can set the static file to be a .ASP file so that I can
> process the data.
> The data is not stored in a database, it's stored in a huge text file
> that is a proprietary format. When the article is published, it's
> published by taking the data from the text file and generating the
> static file with the text.
> Yeah, I know, no database and very old school. But there are over 300
> articles stored in this text file whose format I can't figure out and
> the vendor is out of business and can't help decode it. One purpose
> of this project is to transfer it all in an MS SQL database. The
> stumbling block is the text strings contain quotes.
> A thought - because of the quotes, from what I've read here I think
> that these strings can't be properly processed conventionally. I'm
> considering modifying the templates so that instead of generating
> .ASP files, I'll generate simple .TXT files, then use
> FileSystemObject to read in the text.


That sounds right. One thing though, unless you can preserve the original
locations of the placeholders after the php app does the substitutions, you
will find this to be a difficult task. Perhaps you can modify the template
to look like this?

myString = "{$placeholder$}"

so that after the substitution, it looks like this:

myString = "{The Senator said "It's not my fault", then ran to his
car}"

That will make it a little easier to find the strings to be escaped ... you
may even be able to build a regular expression to do the escaping.

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      08-28-2009
Toni wrote on 28 aug 2009 in microsoft.public.inetserver.asp.general:

> "Evertjan." wrote...


>> ASP/VBscript:
>>
>> theString = replace(theString,"""","""""")

>
> NO, your suggestion generates an error, because if I insert this in
> the template:
> theString = replace($placeholder$,"""","""""")


That is not what I adviced,
I advised to write a variable there:

theString = replace(theString,"""","""""")

> the template will generate this SOURCE CODE:
> theString = replace(The Senator said "It's not my
> fault,"""","""""")
> which will obviously crash.


Is this templating stuff, $...$, something on topic here?

Try:

========================================
<% 'vbs assumed
response.write theString
%>

<script type='text/javascript' runat='server'>
var theString = '$placeholder$';
theString = theString.replace(/"/g,'""');
</script>
=======================================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Toni
Guest
Posts: n/a
 
      08-28-2009
"Bob Barrows" wrote...
>...One thing though, unless you can preserve the original locations of the placeholders
>after the php app does the substitutions,


The app is a Perl CGI application, not PHP.



 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      08-28-2009
Toni wrote:
> "Bob Barrows" wrote...
>> ...One thing though, unless you can preserve the original locations
>> of the placeholders after the php app does the substitutions,

>
> The app is a Perl CGI application, not PHP.


Oops. My point still stands, I think.

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quote-Dot-Quote Operator kvnsmnsn@hotmail.com C++ 6 06-14-2008 11:34 PM
How to handling string contains single quote and double quote vikrant Perl Misc 8 05-17-2007 04:37 PM
Datagrid on load; replace all double single quote to single quote to display to user Eric Layman ASP .Net 3 04-14-2007 07:16 AM
replacing strange quote with standard quote Stimp ASP .Net 2 09-20-2006 10:01 AM
Single Quote Versus Double Quote In A href link knee-dragger@hotmail.com HTML 3 06-13-2006 12:42 AM



Advertisments