0 votes

So I am using the code:

string.count(" ")

But when it runs the code it gives the error:

Method 'count' is not declared on base 'String'.

I checked the godot engine docs and count() is a thing yet it won't work for me. I also tried

"    ".count(" ")

In the _ready(): function as well and still got the same error. Any help would be appreciated

in Engine by (61 points)

1 Answer

0 votes

I tried it by myself:

func _ready():
    var string : String = "Bla Bla Bla"
    print(string.count(" "))
    print("Blubber".count("b"))

is working fine and prints

2
2

as expected.
Can you show more code, maybe the error is somewhere else.

by (1,448 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.