Is there a way to count characters in a array? Like "message[page]" eg. message["hello", "Good Night"]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RyuGold

Is there a way to count characters in a array? Like “message[page]” eg. message[“hello”, “Good Night”]

I’m not sure I understand exactly what you’re after here. Are you just wanting to count all characters in all elements in the array, or something else? Maybe provide a sample array and the “count” value you’d expect to get from it.

jgodfrey | 2022-02-10 00:15

each message in the array is a page like “hello” is page 0 and good night is 1 I wanted to count each one them not all array. I already use get_total_character_count in node “show message” in which there is a rich text label

RyuGold | 2022-02-10 00:21

Sorry, it’s still not clear to me what you’re looking for here. If you could give some very specific examples, that’d be helpful. Something like:

  • Here’s a sample array
  • Using that array, I’d expect the count to be “X”

jgodfrey | 2022-02-10 01:04

![enter image description here][comment3-1]the “message” is an array

https://i.ibb.co/NWXJLRX/Sem-T-tulo-3.jpg

I trying to develop a message system and need to count the characters.

while message <= get_total_character_count
show message

RyuGold | 2022-02-10 01:59

:bust_in_silhouette: Reply From: jgodfrey

Still struggling a bit to understand what you want. However, if you just want to know the length of one of your messages… Each message is just a string. And, a string object has a length function that will tell you how many characters it contains.

So, for example:

var s = "test"
print(s.length())

will print:

4

yes! that is it that I want! but rich text label does not have function length. Please I wanted with an array. But length does not print spaces right?

RyuGold | 2022-02-10 04:20

A RichTextLabel has a text property. That’s the property that stores the text shown in the label. That will be a string, and therefore, will have a length() method.

So, if you have a RichTextLabel as a child component…

$RichTextLabel.text = "Some Sample Text"
var char_count = $RichTextLabel.text.length()
print(char_count)

will print…

16

And, yes, if your string contains spaces, they will also be “counted” via the length function.

jgodfrey | 2022-02-10 04:40