AscII to Int - Int to AscII

Hello *,

for an application I need to get the AscII from a Char (e.g. the third char from a string) like:

var s: string = “Hello”;
var i: int = parseInt( s[2] );

… but this won’t work.

Finally I’d like also to convert an integer to an AscII like:

var s: string = ( 65);

Thank you,
Ulrich

System.Convert.ToInt32/ToChar. Though it’s Unicode and not ASCII.

–Eric

C#

string s = "Hello";
char c = s[0];
int i = c;
		
print(i);

Javascript

var str = "Hello";
var cha = str[0];
var integer:int = cha;
	
print(integer);

Should both display 72 (ASCII H = 72)

Interesting…casting from chars to ints used to not work in Unity 2.

–Eric

Thank you very much. This is what I was looking for. :slight_smile:

Ulrich

But how about convert Unicode back to string?

int i = 72;
char a = Convert.ToChar(i);
print(a);