Operations on ASCII values

Version:

5.0

Added on:

12 Sep 2014 22:42

Tags:

Description:
Although extremely simple, AS documentation never mentions how to perform these operations, so this snippet is to spare your time searching. Function explanations in comments.
  1. uint8 ord(const string &in s) { //Returns the ASCII value of the first character of a string.
  2.   return s.isEmpty() ? 0 : s[0];
  3. }
  4. string chr(uint8 x) { //Returns a one-character string corresponding to an ASCII value.
  5.   string s('0');
  6.   s[0] = x;
  7.   return s;
  8. }