Unicode text to integer conversion from file data
Unicode text to integer conversion from file data
- Subject: Unicode text to integer conversion from file data
- From: Donald Hall <email@hidden>
- Date: Fri, 27 Oct 2006 23:54:44 -0600
Title: Unicode text to integer conversion from file
data
Can anyone explain what is going on here? Result is same on Intel
iMac or PPC iBook (Both Tiger):
-- integer from Unicode text test
on TempFile()
"" & (path to "temp"
from user domain) & "temp_file"
end TempFile
set f to TempFile()
try
set n to open for access file
f with write permission
set testText to "59" as Unicode
text
set eof n to 0
write testText to n
on error errMsg
display dialog
errMsg
end try
close access n
set theFile to (open for access file f)
set theRawData to (read theFile) as Unicode text
close access theFile
display dialog "theRawData is" & return & "|"
& theRawData & "|"
set fifty9 to "59" as Unicode text
set comp to theRawData = fifty9
display dialog "comparison result is:" & comp as
text
try
set problem to
"fifty9"
set n1 to fifty9 as integer
set problem to
"theRawData"
set n2 to theRawData as
integer
display dialog "coercion successful"
on error errMsg
display dialog problem &
": " & errMsg
end try
----------------------------------------------------------
tell current application
path
to "temp" from user domain
alias "Main
Volume:Users:dhall:Library:Caches:TemporaryItems:"
open for access file "Main
Volume:Users:dhall:Library:Caches:TemporaryItems:temp_file"
with write permission
166
set eof 166 to 0
write
"59" to 166
close
access 166
open
for access file "Main
Volume:Users:dhall:Library:Caches:TemporaryItems:temp_file"
167
read 167
"59"
close access 167
display dialog "theRawData is
|59|"
{button returned:"OK"}
display dialog "comparison result
is:true"
{button returned:"OK"}
display dialog "theRawData: Can't make \"59\" into type
integer"
{button returned:"OK"}
end tell
--------------------------------------------------------------------------
Above is copied and pasted from
Script Editor event log.
Thanks to anyone who can explain
this. I need to extract a number from a Unicode text string read
in from a file, but the coercion fails.
Don
--
Donald S. Hall, Ph.D.
Apps & More Software Design, Inc.
email@hidden
http://www.appsandmore.com
_______________________________________________
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/mailman//archives/applescript-users
This email sent to email@hidden