ORD and CHAR in Scratch -


i coming across more , more situations in scratch have convert number acsii character or visa versa. there no built function in blocks this.

my solution create list of size 26 , append letters a-z each sequence using variable called alphabet = "abcdefghijklmnopqrstuvwxyz" , iterating on repeat block , appending letter count of alphabet list.the result list data structure letters a_z between location 1 26.in effect creating own ascii table.

to converson number 26 'z' have iterate on list correct char value. slows down program heavily dependent on chr() feature. there better or more efficient solution?

my solution create list of size 26 , append letters a-z each sequence using variable called alphabet = "abcdefghijklmnopqrstuvwxyz"

stop right there. don't need convert list. can directly string.

to character index easy. use (letter () of []) block.

to index of character more complex. unfortunately, scratch doesn't have built-in way that. here define index of [] in [] custom pseudo-reporter block:

define index of (char) in (str) set [i v] [1] repeat until <<(i) = (length of (str))> or <(letter (i) of (str)) = (char)>>     change [i v] (1) 

view online

you can call block index of [a] in (alphabet) , set i variable 1.

this code doesn't have case if character isn't found, link provided include that, if need.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -