Asc() equivalent. Am I being dumb?

Monkey Forums/Monkey Programming/Asc() equivalent. Am I being dumb?

Grey Alien(Posted 2013) [#1]
I just want to convert a single char to its ASCII int value so I'm doing this:

"A".ToChars()[0]

Is that dumb? Is there a better way (apart from using the actual int or declaring a bunch of ASCII constants?)


ziggy(Posted 2013) [#2]
It's a lot easier to just do:
"A"[0]
This is converted to the character integer number at compile time, so it does not involve calling methods and it's "instant" on execution time


Nobuyuki(Posted 2013) [#3]
neat little trick there.


ziggy(Posted 2013) [#4]
In fact, I can't honestly see a usual need for the ToChars() unless you're going to make some aritmetics with character values. Accesing a character number by index is built-in on Monkey strings.


Grey Alien(Posted 2013) [#5]
Aha thanks, a neat optimisation.