Copy link to clipboard
Copied
Hi,
I put together an interactive HTML5 canvas document.
After a week of fighting multiple snags and learning curves, I finally have a working product! Just when I thought I was done, I am stumped once more after I received the content to update the text with.
I am trying to put the word CO2 in there, but I need the 2 to be subscript.
var string1 = "how much CO";
var string2 = "2";
var substring = string2.sup();
var string3 = " is used?";
_this.inst_text.text = string1 + substring + string3;
It shows up as,
"How many <sub>2</sub> is used."
I need to stick with Dynamic text because I change it out later in code.
Any suggestions?
Thanks!
Hi.
You can use unicodes and the static method fromCharCode from the String class. Like this:
var root = this;
root.charfromUnicode = function(code)
{
return String.fromCharCode(parseInt(code, 16));
};
console.log("CO" + root.charfromUnicode(2082));
I hope this helps.
Regards,
JC
Copy link to clipboard
Copied
Hi.
You can use unicodes and the static method fromCharCode from the String class. Like this:
var root = this;
root.charfromUnicode = function(code)
{
return String.fromCharCode(parseInt(code, 16));
};
console.log("CO" + root.charfromUnicode(2082));
I hope this helps.
Regards,
JC
Copy link to clipboard
Copied
You Rock!
That worked no problem.
Thanks very much for the prompt reply.
Take care!
Copy link to clipboard
Copied
Excellent! You're welcome!