Re: coerce record to string - does this work in other System languages?
Re: coerce record to string - does this work in other System languages?
- Subject: Re: coerce record to string - does this work in other System languages?
- From: "Nigel Garvey" <email@hidden>
- Date: Thu, 25 Mar 2010 21:12:53 +0000
Skeeve wrote on Thu, 25 Mar 2010 20:48:21 +0100:
>Hi!
>
>I wrote this little handler to coerce a record into a string. It works
>with "German" as System language. Does it work with other languages too?
>Who can test?
>
>display dialog to_String(info for POSIX file "/tmp")
>
>on to_String(the_record)
> try
> {a:0} as string
> on error cutoff
> set cutoff to 4 - (length of cutoff)
> end try
> try
> the_record as string
> on error the_record
> set the_record to text 1 thru cutoff of the_record
> end try
> return the_record -- as string
>end to_String
This should work (for records with at least one item) on any system:
display dialog to_String(info for POSIX file "/tmp")
on to_String(the_record)
try
the_record as string
on error the_record
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "{"
set the_record to "{" & text from text item 2 to -1 of the_record
set AppleScript's text item delimiters to "}"
set the_record to text 1 thru text item -2 of the_record & "}"
set AppleScript's text item delimiters to astid
end try
return the_record
end to_String
As from Snow Leopard, multiple delimiters are possible:
display dialog to_String(info for POSIX file "/tmp")
on to_String(the_record)
try
the_record as string
on error the_record
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"{", "}"}
set the_record to "{" & text from text item 2 to text item -2 of
the_record & "}"
set AppleScript's text item delimiters to astid
end try
return the_record
end to_String
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden