1) PDFs in database 2) copy/paste from Excel

Gary, thank you again. That’s great.

I modified your code a little bit, so it will ask for input and will respond with any encoded and decoded character.

local urlChar, input
gettext "Enter special character!", input
urlChar=radixstr("hex",texttobinary(input))
urlChar="%"+urlChar[1,2]+"%"+urlChar[3,4]+sandwich("%",urlChar[5,6],"")
message urlChar  // encoded character
message hextobinary(replace(urlChar,"%",""))  // decoded character

Ok, here is some code that will percent encode all the high utf-8 characters with a value over 255 for any entered URL.

local urlStart, urlEncoded
urlStart="" urlEncoded=""
supergettext urlStart,{height=120width=488 title="Enter your URL!"}
if info("dialogtrigger")="Cancel" stop endif
characterfilter urlStart,urlEncoded, ?(asc(import())>255,
    "%"+radixstr("hex",texttobinary(import()))[1,2]+
    "%"+radixstr("hex",texttobinary(import()))[3,4]+
    sandwich("%",radixstr("hex",texttobinary(import()))[5,6],""),import())
message urlEncoded

Finally, this version duplicates the percentescape( function but is able to handle any utf-8 character even those above 255.

local urlStart, urlEncoded, charList
urlStart="" urlEncoded="" charList=""
supergettext urlStart,{height=120width=488 title="Enter your URL!"}
if info("dialogtrigger")="Cancel" stop endif
supergettext charList,{height=80width=250 title="Enter special escape list (&^ ®)" buttons="Ok"}
characterfilter urlStart,urlEncoded, ?(charList contains import(),
    "%"+radixstr("hex",texttobinary(import()))[1,2]+
    sandwich("%",radixstr("hex",texttobinary(import()))[3,4],"")+
    sandwich("%",radixstr("hex",texttobinary(import()))[5,6],""),import())
message urlEncoded

That’s it I promise.

1 Like

In your first sample there was an error with the right parenthesis and the text funnels. You noticed it already: Your second sample has the correct code.

In my personal modification I have changed the character number from “>255” to “>127” to let the code encode German umlauts like “ä”, “ö”, “ü”, too.

But in your new code, what is the purpose of the line supergettext charList … ?

The percentescape( function has two parameters - TEXT & ESCAPELIST. The first parameter is the text string that will be used for encoding while the second parameter is a list of the special characters you want to be encoded. My charList input is for you to list the characters that you want encoded within the text. Percentescape( gets this list from the second parameter while I have you input it directly in the supergettext dialog. If this code was converted to a custom function then these would would be parameters as well and urlStart would be set to the value of parameter(1) while charList would be set to parameter(2).

Sorry if I still don’t understand: The percentescape( function does not exist in your code. And your variable charList seems not to be used in the formula of the characterfilter statement.

The idea that inspired me to work out the code was because the existing percentescape( function did not only not encode characters over 255 but would actually not output anything if such a character was entered for encoding and would stop the procedure in which it was executed. My above rendition is just a replacement scheme for the percentescape( function and would thus not have that function in the code. Sorry if not very clear in my explanation.