Getting unicode (or ascii) number for a character

Hey guys,

I was wondering… there are Graham’s extensions to go from unicode names (“unicode Hebrew letter alef”) or numerical values (“unicode 321”) to a single character, but is there a way to go back? To get a unicode numerical value from an actual character?

Or just getting ascii for characters that are “plain”, that would work too.

// Peter

PS. MTW’s threat to kick me off our google group worked! I’m back writing I7 again, and I haven’t forgotten it all.

The I7 type “unicode character” is internally an integer. So that conversion is trivial. I don’t remember off-hand how to extract a character from a text.

Just had to prod ya to make sure you were still kickin’! :wink:

Trivial it may be, but I still don’t know how to do it. Can I cast a character to a number somehow?

This code does not work:

N is a number that varies.

when play begins: 
	let C be character number 1 in "abc";
	now N is C;
	say "Character [C] -> [N]";

I get this error message:

Maybe the problem is that “character number 1 in ‘abc’” is still a text, and not a character?

Yes, “character number…” is a text of length one.

I could tell you that the trivial conversion is

To decide what number is the ordinal of (ch - unicode character): (- ({ch}) -).

But this still leaves you with the hard part of the problem. Sorry. One day I will have to work out I7’s internal string handling.

Ok, nvm. I can just put a selection of character codes in a table and match them that way. I just need letters and numbers really.

Thanks!