Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Animate CC HTML5 Canvas subscript

Community Beginner ,
Feb 11, 2021 Feb 11, 2021

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!

419
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 11, 2021 Feb 11, 2021

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 

Translate
Community Expert ,
Feb 11, 2021 Feb 11, 2021

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 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 11, 2021 Feb 11, 2021

You Rock!

 

That worked no problem. 

 

Thanks very much for the prompt reply.

 

Take care!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2021 Feb 11, 2021
LATEST

Excellent! You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines