Asc() equivalent. Am I being dumb?
Monkey Forums/Monkey Programming/Asc() equivalent. Am I being dumb?
| ||
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?) |
| ||
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 |
| ||
neat little trick there. |
| ||
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. |
| ||
Aha thanks, a neat optimisation. |