Returns the position of a given sub-string in a string.


GML Code Example

string_pos(substr, str);

Argument Description
substr The substring to look for in the string.
str The string.

Returns: Real


This function will return the character position of an instance of a sub-string within a string, or 0 if it's not found at all. 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.


GML Code Example

if string_pos(",", text) != 0
    string_insert(name, text, string_pos(",", text));

The above code searches the string "text" for a comma, and if it finds one it inserts the substring "name" at that position.

Back: Strings

No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here