|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
aagoldberg |
I’m trying to check if a user types a specific word in LineEdit. I have the word as a value in a dictionary, and I’ve used the command if word in new_text (users input), but that only check if the users input is equal to the word.
|
|
|
|
Reply From: |
alfandango |
You can try using a Regular expression to match the word in a sentence. I haven’t actually used Godot’s regex object myself but it does have one.
Alternatively, you would have to slice the sentence into a new array of words and then loop through each, compare to your dictionary to find a match.
|
|
|
|
Reply From: |
hilfazer |
Try these methods of String class
int find ( String what, int from=0 )
Finds the first occurrence of a substring. Returns the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.
int find_last ( String what )
Finds the last occurrence of a substring. Returns the starting position of the substring or -1 if not found.
int findn ( String what, int from=0 )
Finds the first occurrence of a substring, ignoring case. Returns the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.