This function will return the character position of an instance of a sub-string within a string, searching from the beginning of the string (to search from the end, use the function string_last_pos()). The function will return 0 if it's not found at all, or the position of the first character of the sub-string if it is found. Keep in mind that for legacy support strings are indexed from 1, so 1 is the first position in the string, not 0 as you may expect. One use for this is for filtering words that may be considered offensive, or for finding the correct place to insert some text into another string.
string_pos(substr, str);
Argument | Type | Description |
---|---|---|
substr | String | The substring to look for in the string. |
str | String | The string. |
if (string_pos(",", text) != 0)
{
string_insert(name, text, string_pos(",", text));
}
The above code searches the string stored in the variable "text" for a comma, and if it finds one it inserts the substring "name" at that position.