Search code examples
smalltalkpharomit-scratch

Pharo: How to convert ASCII character into ASCII decimal


I'm making a Scratch 1.4 mod using Smalltalk (from MIT) and researching this got me absolutely nowhere.

Converting ASCII characters seems easy, but how do you do it in Smalltalk?

If you have no clue, the ASCII number of 65 should give you "A" (don't quote me on that.)

If this seems utterly stupid to ask, it took me 2 days worth of time to research and find out how to add a function in Smalltalk. That's how much I have been struggling on this, as I know very little about Smalltalk, but I plan to extend this knowledge.


Solution

  • In case you don't get a more specific answer for Scratch, here's what works in Pharo (which was forked from Squeak, which is what Scratch is based on):

    To convert from a character to its ascii value, just as for its... you guessed it, asciiValue:

    $A asciiValue (which evaluates to 65)

    To convert from an integer/ascii value to a character, just create a new character object with that value:

    Character value: 65 (which evaluates to $A)

    I don't think this is Pharo-specific, so should work in Squeak (and therefore in Scratch) as well.