• 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: Routines for review: Hex <-> String
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Routines for review: Hex <-> String


  • Subject: Re: Routines for review: Hex <-> String
  • From: julifos <email@hidden>
  • Date: Sat, 18 Jan 2003 12:08:26 +0100

>> This is a cool method if you're running Smile, but... Why do you think the
>> error msg "is rather fragile"? Error messages could change its syntax, but
>> did they until now?
>
> I stated so because I was thinking the error message might be
> different depending on the language, but maybe I'm missing something
> huge here - it has happened in the past, ?verdad? :-)
>
> Emmanuel

I don't know? A japanese system should return japanese errors? I don't know.
Can't test it ;-)
Anyway, we can throw an error where we look for the offset of "<<" & ">>" or
where the first word is our data:

"Hello" as C string (or Pascal)
try
exists result
on error msg
--> msg = "<<data cstr48656C6C6F00>> whatever language."
--> play with msg's word 2
end try

But perhaps looking for | (offset of "<<" in msg) + 10 | & | (offset of ">>"
in msg) - 1 | is more accurate...

> I like this.
>
> set hex to stringtoHex("hello world")
> -->{"68", "65", "6c", "6c", "6f", "20", "77", "6f", "72", "6c", "64"}
> set AppleScript's text item delimiters to "%"
> HexToString("%" & hex)
> -->"hello world"
> set AppleScript's text item delimiters to ""
>
>
> on stringtoHex(s)
> words 2 thru ((length of s) + 1) of (do shell script "echo " & s & " |
> hexdump -C")
> end stringtoHex

Very short code! But this routine is very slow and it won't handle large
strings, unless you say:

text from word 2 of x to word y of x

(quick note off-topic: I've seen that
text from character 1 of x to character 5 of x
If much quicker than
characters 1 thru 5 of x as string
)

> on HexToString(h)
> do shell script "echo " & h & " | perl -ple
> 's/%([0-9a-fA-F]{2})/chr(hex($1))/ge' "
> end HexToString

Hmmm... This doesn't work for me... Do I need install something? It returns:
--> "h656c6c6f20776f726c64"

JJ
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Routines for review: Hex <-> String
      • From: Paul Skinner <email@hidden>
  • Prev by Date: Re: Need Root Access to etc/rc
  • Next by Date: Re: Why does the Script Editor Service do this?
  • Previous by thread: Re: Routines for review: Hex <-> String
  • Next by thread: Re: Routines for review: Hex <-> String
  • Index(es):
    • Date
    • Thread