See if a string contains a substring from a set of words

T

tamation

Guest
I have a ds_list full of words I want to check for, I know that you can use string_count to see if a certain substring appears in a string, but is there a way to set it up so that I can check for if any phrases in the ds_list appears in the string without manually checking each one individually?
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
Here you have it!

Code:
///string_match_from_list(string, list)

var _string = argument0, _list = argument1;

var _length = ds_list_size(_string)
for (var _i = 0; _i < _length, _i++)
{
     _sub = _list[| _i];
     if (string_count(_sub, _length) > 0) return _i;
}
return -1;
if there is a match the functions returns the index of the match in the list.
NOTE: the script stops on first match.
 

obscene

Member
Sidenote on the above in case you missed it, it returns the list position and not true/false so a 0 would mean it found something.
 
Top