× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



At 01:43 PM 11/8/02, you wrote:
The archives are down...  I have an urgent need... <g>

I've got to take a string from a user input and surround it in quotes.
The problem arises when the string itself has a quote or multiple
quotes in it.  So if a user keys in:
  Don's in deep doo-doo with deleting Dave's files.
Just encode the string by checking each byte.  If the byte is a special
character, replace it.  Here is the encode routine I use for creating XML
documents, you should be able to use it with just a few changes:

       *****************************************************************
       * XML encode special characters
       *****************************************************************

      P xml_encode      b                   export

      D xml_encode      pi           512    Varying
      D  buffer                      512    Varying Const

      D  encoded        S            512    Varying
      D  max            S             10u 0
      D  i              S             10u 0
      D  byte           S              1

       * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       * encode bytes
      C                   eval      max = %len(buffer)
      C     1             do        max           i
      C                   eval      byte = %subst(buffer:i:1)
      C                   select
      C     byte          wheneq    '&'
      C                   eval      encoded = encoded + '&amp;'
      C     byte          wheneq    ''''
      C                   eval      encoded = encoded + '&apos;'
      C     byte          wheneq    '"'
      C                   eval      encoded = encoded + '&quot;'
      C     byte          wheneq    '<'
      C                   eval      encoded = encoded + '&lt;'
      C     byte          wheneq    '>'
      C                   eval      encoded = encoded + '&gt;'
      C                   other
      C                   eval      encoded = encoded + byte
      C                   endsl

      C                   enddo

      C                   return    encoded

      P xml_encode      e



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.