- Home /
int to char conversion in JS ?
Hi!
Casting a char to int (goal: "A" becomes 65) works. But how can I simply cast an int to a String, in JS? (goal:65 should become "A")
Thanks!
Comment
Best Answer
Answer by whydoidoit · Jun 22, 2012 at 09:19 AM
Just like this:
var a : char = 65;
Face pal$$anonymous$$g... Was trying myString[0] = 65, compiler said String.Chars are readOnly. But myString += a works... Thanks!
Answer by gregzo · Jun 22, 2012 at 09:57 AM
In case anyone's in a similar use case, here's some code to convert a list of enum (here Notes) to a string and back. I use it to send a list as an RPC parameter.
function NotesToString(notes:List.<Notes>)
{
var noteString : String = "";
var noteChar : char;
for(note in notes)
{
noteChar = parseInt(note);
noteString+=noteChar;
}
return(noteString);
}
function StringToNotes(str : String)
{
var notes = List.<Notes>(str.length);
var noteInt : int;
var note : Notes;
for(s in str)
{
noteInt = s;
note = noteInt;
notes.Add(note);
}
return notes;
}
Your answer
Follow this Question
Related Questions
Error CS0029 fix 1 Answer
Extract number from string? 3 Answers
Download a WWW int? Or convert? 1 Answer