[SOLVED] How can I read the length of a text paragraph?

When the content of a text paragraph varies in real time, is there a way I can figure the length of this paragraph? Like # of characters or something?

Hi @lenvanthis,

Yes, text is string property, you can read its length (number of characters) like this:

const noOfChars = this.entity.element.text.length;
2 Likes
let storyName = names[0]+".story";
                console.log(storyName);
                let story = this.app.assets.find(storyName);
                if (story != null){
                    painting.story = story.resource;
                    console.log("FOUND A STORY " + painting.story.entity.element.text.length); // <<<=====
                } else {
                    console.log("DOESN'T EXIT" + storyName);
                }

story.entity.element.text.length
or any other combinations I have tried didn't work.

Any idea?

Hey @lenvanthis,

As Leonidas mentioned, entity.element.text.length should return you the number of characters in the text element.

I see you’re loading the resource of an asset. Are you sure this resource is an entity?

Yes. It is. It is a text file ending .story. Ex) file.story
I know it is read correctly since the content is changed according the text.
I am reading this usning script “textDisplay”.

So the asset you are loading is a text file, not an entity? In that case, you can simply call story.resource.length.

2 Likes

That was the on point solution. Thank you.