Strfind

From SA-MP Wiki

Jump to: navigation, search


Search for a sub string in a string.


Parameters:
(const string[],const sub[],bool:ignorecase=false,pos=0)
const string[]The string you want to search in (haystack).
const sub[]The string you want to search for (needle).
ignorecase (optional)When set to true, the case doesn't matter - HeLLo is the same as Hello. When false, they're not the same.
Position (optional)The offset to start searching from.


ReturnsThe number of characters before the sub string (the sub string's start position) or -1 if it's not found.


if(strfind("Are you in here?", "you", true) != -1) //returns 4 (!= -1 because -1 would be 'not found')
{
    SendClientMessageToAll(0xFFFFFFFF, "I found you!");
}

Related Functions

The following functions may be useful, as they are related to this function in one way or another.

  • Strcmp: Compare two strings to check if they are the same.
  • Strtok: Get the next word/parameter in a string.
  • Strdel: Delete part of a string.
  • Strins: Insert text into a string.
  • Strlen: Get the length of the string.
  • Strmid: Extract part of a string into another string.
  • Strpack: Pack a string into a destination.
  • Strval: Convert a string into an integer.
  • Strcat: Concatenate two strings into a destination reference.
Personal tools
In other languages