Notifications
Clear all

[Closed] ord() + chr() for maxScript

 rdg

I couldn’t find this functions for max script.

I developed this litte struct to mimic their behaviour.
Please note that only ASCII values greater than 32 are implemented


struct __rdgStringFunc (
	theASCIItable = #(" ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "", "€", "", "‚", "ƒ", "„", "
", "†", "‡", "ˆ", "‰", "Š", "‹", "Œ", "", "Ž", "", "", "‘", "’", "“", "”", "•", "–", "—", "˜", "™", "š", "›", "œ", "", "ž", "Ÿ", " ", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "*", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ"),
	fn chr input = (
	 return (theASCIItable[(input-31)])
	),
	fn ord input = (
		return ((findItem theASCIItable (input))+31)
	)

)
global rdgStringFunc = __rdgStringFunc()

If you place the file rdgStringFunc.ms in sour scripts/startup folder you can acces them like this:


print (rdgStringFunc.chr 75) -- returns K
print (rdgStringFunc.ord "*") -- returns 42

Here is a PHP snipped to produce the ASCII-array:
tableGenerator.txt

Maybe somebody with c++/c#/activeX knowledge can write a maxscript extension?
This could be faster … I don’t know …

Georg

1 Reply
 rdg

just because I didn’t find them, that doesn’t mean they don’t exist.

the functions are called:
bit.intAsChar and bit.charAsInt

letter = "A"
format "% %
" letter (bit.intAsChar ((bit.charAsInt letter) + 32))

Georg