Handling a literal string with a quote

Discussion in 'ASP General' started by Toni, Aug 27, 2009.

  1. Toni

    Toni Guest

    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!!!
     
    Toni, Aug 27, 2009
    #1
    1. Advertising

  2. Toni

    Evertjan. Guest

    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)
     
    Evertjan., Aug 27, 2009
    #2
    1. Advertising

  3. Toni

    Toni Guest

    "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.
     
    Toni, Aug 27, 2009
    #3
  4. Toni

    Bob Barrows Guest

    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"
     
    Bob Barrows, Aug 28, 2009
    #4
  5. Gazing into my crystal ball I observed "Toni" <> writing
    in news::

    > 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
     
    Adrienne Boswell, Aug 28, 2009
    #5
  6. Toni

    Toni Guest

    "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.
     
    Toni, Aug 28, 2009
    #6
  7. Toni

    Bob Barrows Guest

    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"
     
    Bob Barrows, Aug 28, 2009
    #7
  8. Toni

    Evertjan. Guest

    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)
     
    Evertjan., Aug 28, 2009
    #8
  9. Toni

    Toni Guest

    "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.
     
    Toni, Aug 28, 2009
    #9
  10. Toni

    Bob Barrows Guest

    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"
     
    Bob Barrows, Aug 28, 2009
    #10
  11. Toni

    Toni Guest

    "Evertjan." <> wrote in message
    news:Xns9C75A971976F5eejj99@194.109.133.242...
    > 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>
    > =======================================


    No, it needs to be ASP. Please read the rest of the discussion.
     
    Toni, Aug 28, 2009
    #11
  12. Toni

    Evertjan. Guest

    Toni wrote on 28 aug 2009 in microsoft.public.inetserver.asp.general:

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

    >
    > No, it needs to be ASP. Please read the rest of the discussion.


    THIS IS ASP AND ONLY ASP!!

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 28, 2009
    #12
  13. Toni

    Neil Gould Guest

    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.
    >
    > 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!!!
    >

    After reading all of the responses so far, I agree with Bob Barrows that you
    will need to parse and qualify the input strings as an independent operation
    prior to insertion into your MS SQL database, since other formatting
    considerations such as apostrophes and accents might also impact this
    process, not just quotes. I don't see a "quick and dirty" one-step approach
    that will be reliable. You should be able to parse the strings with VB or JS
    with your ASP pages, but it will likely require a number of qualification
    steps.

    Best,

    --
    Neil Gould
    Terra Tu Technical Publishing
    www.TerraTu.com
     
    Neil Gould, Aug 29, 2009
    #13
  14. Toni

    Evertjan. Guest

    Neil Gould wrote on 29 aug 2009 in
    microsoft.public.inetserver.asp.general:

    > 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.
    >>
    >> 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!!!
    >>

    > After reading all of the responses so far, I agree with Bob Barrows
    > that you will need to parse and qualify the input strings as an
    > independent operation prior to insertion into your MS SQL database,
    > since other formatting considerations such as apostrophes and accents
    > might also impact this process, not just quotes.


    Not if you use parametric insertion.

    > I don't see a "quick
    > and dirty" one-step approach that will be reliable. You should be able
    > to parse the strings with VB or JS with your ASP pages, but it will
    > likely require a number of qualification steps.




    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 29, 2009
    #14
  15. Toni

    Toni Guest

    "Evertjan." <> wrote in message
    news:Xns9C765724558Beejj99@194.109.133.242...
    > Toni wrote on 28 aug 2009 in microsoft.public.inetserver.asp.general:
    >
    >>> ========================================
    >>> <% 'vbs assumed
    >>> response.write theString
    >>> %>
    >>>
    >>> <script type='text/javascript' runat='server'>
    >>> var theString = '$placeholder$';
    >>> theString = theString.replace(/"/g,'""');
    >>> </script>
    >>> =======================================

    >>
    >> No, it needs to be ASP. Please read the rest of the discussion.

    >
    > THIS IS ASP AND ONLY ASP!!


    YOUR CAPS LOCK KEY IS STUCK!!
     
    Toni, Nov 9, 2009
    #15
  16. Toni

    Evertjan. Guest

    Toni wrote on 09 nov 2009 in microsoft.public.inetserver.asp.general:

    >> Toni wrote on 28 aug 2009 in microsoft.public.inetserver.asp.general:
    >>
    >>>> ========================================
    >>>> <% 'vbs assumed
    >>>> response.write theString
    >>>> %>
    >>>>
    >>>> <script type='text/javascript' runat='server'>
    >>>> var theString = '$placeholder$';
    >>>> theString = theString.replace(/"/g,'""');
    >>>> </script>
    >>>> =======================================
    >>>
    >>> No, it needs to be ASP. Please read the rest of the discussion.


    The above is ASP and from August.

    Please attribute quotes correctly.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Nov 9, 2009
    #16
  17. Toni

    Toni Guest

    "Evertjan." wrote...
    > Toni wrote on 09 nov 2009 in microsoft.public.inetserver.asp.general:
    >
    >>> Toni wrote on 28 aug 2009 in microsoft.public.inetserver.asp.general:
    >>>
    >>>>> ========================================
    >>>>> <% 'vbs assumed
    >>>>> response.write theString
    >>>>> %>
    >>>>>
    >>>>> <script type='text/javascript' runat='server'>
    >>>>> var theString = '$placeholder$';
    >>>>> theString = theString.replace(/"/g,'""');
    >>>>> </script>
    >>>>> =======================================
    >>>>
    >>>> No, it needs to be ASP. Please read the rest of the discussion.

    >
    > The above is ASP and from August.
    >
    > Please attribute quotes correctly.


    Please remember to include your previous text in your reply, or start a new subthread.
     
    Toni, Nov 10, 2009
    #17
  18. Toni

    Evertjan. Guest

    Toni wrote on 10 nov 2009 in microsoft.public.inetserver.asp.general:

    >
    > "Evertjan." wrote...
    >> Toni wrote on 09 nov 2009 in microsoft.public.inetserver.asp.general:
    >>
    >>>> Toni wrote on 28 aug 2009 in
    >>>> microsoft.public.inetserver.asp.general:
    >>>>
    >>>>>> ========================================
    >>>>>> <% 'vbs assumed
    >>>>>> response.write theString
    >>>>>> %>
    >>>>>>
    >>>>>> <script type='text/javascript' runat='server'>
    >>>>>> var theString = '$placeholder$';
    >>>>>> theString = theString.replace(/"/g,'""');
    >>>>>> </script>
    >>>>>> =======================================
    >>>>>
    >>>>> No, it needs to be ASP. Please read the rest of the discussion.

    >>
    >> The above is ASP and from August.
    >>
    >> Please attribute quotes correctly.

    >
    > Please remember to include your previous text in your reply, or start
    > a new subthread.


    Don't write nonsense,
    and inpolite to state that I should remember,
    since it is a bout sparse quoting.

    The skipped text wes inconsequential
    to your error in understanding what is ASP and what isn't.

    And waiting more than 2 months befor responding seems strange.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Nov 13, 2009
    #18
  19. Toni

    Toni Guest

    "Evertjan." <> wrote in message
    news:Xns9CC2B539444D1eejj99@194.109.133.242...
    > Toni wrote on 10 nov 2009 in microsoft.public.inetserver.asp.general:
    >
    >>
    >> "Evertjan." wrote...
    >>> Toni wrote on 09 nov 2009 in microsoft.public.inetserver.asp.general:
    >>>
    >>>>> Toni wrote on 28 aug 2009 in
    >>>>> microsoft.public.inetserver.asp.general:
    >>>>>
    >>>>>>> ========================================
    >>>>>>> <% 'vbs assumed
    >>>>>>> response.write theString
    >>>>>>> %>
    >>>>>>>
    >>>>>>> <script type='text/javascript' runat='server'>
    >>>>>>> var theString = '$placeholder$';
    >>>>>>> theString = theString.replace(/"/g,'""');
    >>>>>>> </script>
    >>>>>>> =======================================
    >>>>>>
    >>>>>> No, it needs to be ASP. Please read the rest of the discussion.
    >>>
    >>> The above is ASP and from August.
    >>>
    >>> Please attribute quotes correctly.

    >>
    >> Please remember to include your previous text in your reply, or start
    >> a new subthread.

    >
    > Don't write nonsense,
    > and inpolite to state that I should remember,
    > since it is a bout sparse quoting.
    >
    > The skipped text wes inconsequential
    > to your error in understanding what is ASP and what isn't.
    >
    > And waiting more than 2 months befor responding seems strange.
    >
    > --
    > Evertjan.


    "a bout sparse quoting"?

    Don't write nonsense.
     
    Toni, Jan 28, 2010
    #19
  20. Toni

    Evertjan. Guest

    Toni wrote on 28 jan 2010 in microsoft.public.inetserver.asp.general:

    > "Evertjan." <> wrote in message
    > news:Xns9CC2B539444D1eejj99@194.109.133.242...


    >> And waiting more than 2 months befor responding seems strange.


    [please do not quote signatures on usenet]

    > "a bout sparse quoting"?


    Boutly but slowly going where where many have gone before ?

    > Don't write nonsense.


    You must be the slowest man on Usenet, Toni,
    now this being in response to my posting of 13 Nov 2009 16:48:55 GMT.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jan 30, 2010
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    13,244
  2. Stimp
    Replies:
    2
    Views:
    2,272
    Stimp
    Sep 20, 2006
  3. Eric Layman
    Replies:
    3
    Views:
    630
    Rad [Visual C# MVP]
    Apr 14, 2007
  4. Replies:
    6
    Views:
    442
    Stefan Ram
    Jun 15, 2008
  5. vikrant
    Replies:
    8
    Views:
    366
    vikrant
    May 17, 2007
Loading...

Share This Page