• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ASCII
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ASCII


  • Subject: Re: ASCII
  • From: "Arthur J Knapp" <email@hidden>
  • Date: Fri, 19 Jan 2001 11:33:08 -0500

> Date: Fri, 19 Jan 2001 00:17:02 +0100
> From: Emmanuel <email@hidden>
> Subject: Re: ASCII

> At 23:44 +0100 18/01/01, Arthur J Knapp wrote:

>> Here is my rather interesting way to do it.

>>to hexify_via_file(str)

>> -- Create a temporary file
>> [...]

>> --> +data rdat416243644566476849;
>>> [...]


> For a short string, when it comes to make it into +data xxxxHHHHHHHH;, it
> may be faster not to use a file:

> set theString to "Yes."
> set theData to theString as C string -- no good if the data contains ASCII 0
> -- +data cstr5965732E00; -- chop off last byte, it's 0

> set theString to "Yes."
> set theData to theString as Pascal string -- no good if the length > 255
> -- +data pstr045965732E; -- drop first byte, it's the length

YES!!!

Thank you, Emmanuel. I forgot about the C string and Pascal string
coercions that became available with ? OS 8.5 ?

For a long time, I had wondered why I couldn't simply say:

"a string" as data

but these coercions essentially allow this.

So, new and improved:



to hexify(str, make_list)

-- make_list == false, return "00FF..."
-- true, return {"00", "FF", ...}

-- pretend str == "Howdy"

set str to str as C string
-- > <<data cstr486F77647900>>

try
foo of str
on error err
-- > err == "Can't get foo of <<data cstr486F77647900>>."

set str to err's text 28 thru -5 -- deleting end null
-- > "486F776479"
end try

if (make_list) then
set lst to {}
repeat with x from 1 to ((str's length) - 1) by 2
set end of lst to str's text x thru (x + 1)
end repeat
return lst
else
return str
end if
end hexify

to dehexify(str)
-- str "66FF..."
-- "fÿ..."
-- "$66ÿ..."

repeat with i in {"%", "$"}
if (str contains i's contents) then
set AppleScript's text item delimiters to {i's contents}
set str to str's text items
set AppleScript's text item delimiters to {""}
set str to str as string
end if
end repeat

-- str == "00FF..."

return run script (ASCII character 199 & "data TEXT" & str & ASCII
character 200)

end dehexify


--
{
Arthur J Knapp, of STELLARViSIONs ;

http://www.STELLARViSIONs.com ;

mailto:email@hidden ;

how many?
zero.
are you sure?
i counted twice.
}


  • Prev by Date: Re: Keyboard Question?
  • Next by Date: Re: ASCII (Propellorhead 101)
  • Previous by thread: Re: ASCII
  • Next by thread: How do I .....
  • Index(es):
    • Date
    • Thread