Stata 15 help for mf_char

[M-5] ascii() -- Manipulate ASCII and byte codes


real rowvector ascii(string scalar s)

string scalar char(real rowvector c)


ascii(s) returns a row vector containing the ASCII codes (0-127) and byte codes (128-255) corresponding to s. For instance, ascii("abc") returns (97, 98, 99); ascii("café") returns (99, 97, 102, 195, 169). Note that the Unicode character "é" is beyond ASCII range. Its UTF-8 encoding requires 2 bytes and their byte values are 195 and 169.

char(c) returns a UTF-8 encoded string consisting of the specified ASCII and byte codes. For instance, char((97, 98, 99)) returns "abc", and char((99, 97, 102, 195, 169)) returns "café".


ascii(s): s: 1 x 1 result: 1 x strlen(s)

char(c) c: 1 x n, n>=0 result: 1 x 1


ascii(s) returns J(1,0,.) if strlen(s)==0.

In char(c), if any element of c is outside the range 0 to 255, the returned string is terminated at that point. For instance, char((97,98,99,1000,97,98,99))=="abc".

char(J(1,0,.)) returns "".

Source code

Functions are built in.

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index