Text for Unity, Super-Powered! · By KaiClavier
May I ask is there a way to count the words, line, and words in a line in STM by script?
Yes, there are some hidden values in STM that should give you these values, but you can do some tricks with string.Split, too!
"stm.lineBreaks.Count" should give the amount of lines. "stm.hyphenedText.Split('\n').Length" should also return the same value.
"stm.hyphenedText.Split(' ').Length" should give the amount of words, by counting the amount of spaces in the final text shown.
Words in a line is a bit trickier, but you can use the info from the lineBreaks list (this list contains the indexes of line breaks in hyphenedText) to do this.
This is some really rough untested code, but something like this will give the amount of words in the first line of text:
string line1string = stm.hyphenedText.Split('\n'); //get all text before first linebreak
int line1wordCount = line1string.Split(' ').Length;
I hope this helps!
Great, this helps a lot! Thanks.
I found it especially useful when the different lineBreaks information stored in text and hyphened text are used together :)