|
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 + '&' C byte wheneq '''' C eval encoded = encoded + ''' C byte wheneq '"' C eval encoded = encoded + '"' C byte wheneq '<' C eval encoded = encoded + '<' C byte wheneq '>' C eval encoded = encoded + '>' 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 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.