Get Unicode code point

I need to be able to force a string to type TEXT. The only way to that that I can find is to use «data TEXT». In order to do that I need to retrieve the Unicode code points for each character in the string. For example, the id property returns 65 for the upper case A. If I then plug that into «data TEXT» the result is lower case e. The Unicode code point for upper case A is actually 0041. Is there a way to convert between the output of id and what «data TEXT» is expecting?

set a to “A”
set b to id of a → 65
set c to «data TEXT65» → e

Hi,

id of returns a decimal value while <data TEXT expects an hexadecimal value

decimal 65 is equal to hexadecimal 41

Thanks, figured it out. Just need to convert to hex.

«data TEXT.» is the old ‘string’ class. While it’s in your script, it may as well be Unicode text anyway. But you can write TEXT data directly to file with the File Read/Write commands:

set a to "A"
set fRef to (open for access file ((path to desktop as text) & "Test.txt") with write permission)
try
	set eof fRef to 0
	write a as string to fRef -- or as «class TEXT» or as "TEXT".
	-- Read the byte back two different ways to see how it looks in each case.
	set dat to (read fRef from 1 as data)
	set str to (read fRef from 1 as string) -- or as «class TEXT» or as "TEXT".
end try
close access fRef

{dat, str} --> {«data rdat41», "A"}

Characters which don’t have 8-bit equivalents are replaced with question marks.