Strfind

From SA-MP Wiki

Jump to: navigation, search

strfind

Image:Farm-Fresh text lowercase.png Note: This function name starts with a lowercase letter.


Description:

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.


Return Values:

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


Example Usage:

if(strfind("Are you in here?", "you", true) != -1) //returns 4, because the start of 'you' (y) is at index 4 in the string
{
    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 'token' (word/parameter) in a string.
  • strdel: Delete part of a string.
  • strins: Insert text into a string.
  • strlen: Get the length of a string.
  • strmid: Extract part of a string into another string.
  • strpack: Pack a string into a destination string.
  • strval: Convert a string into an integer.
  • strcat: Concatenate two strings into a destination reference.
Personal tools
In other languages