ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:strfind

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
functions:strfind [2017/03/20 09:54] – created korshunfunctions:strfind [2020/12/24 13:12] (current) – [Examples] monsterovich
Line 4: Line 4:
  
 ===== Description ===== ===== Description =====
-Returns the position of what in s. If the string is not present, returns -1. +Returns the position of the first occurence of what in s. If the string is not present, returns -1.
  
 +<note tip>To search for the **last** occurence, use [[StrRFind]].</note>
  
 ===== Examples ===== ===== Examples =====
 <code> <code>
-StrFind("abcdef", "def") -> 3 +StrFind("abcdefabc", "def") -> 3 
-StrFind("abcdef", "abc") -> 0 +StrFind("abcdefabc", "abc") -> 0 // First occurence 
-StrFind("abcABCabc", "ABC") -> 3 +StrFind("abcdef", "xyz") -> -1   // Not found 
-StrFind("abcdef", "xyz") -> -1+StrFind("abcABCabc", "ABC") -> 3 // Case-insensitive 
 +StrFind("ab", "abc") -> -1 // Not found 
 +StrFind("", "abc") -> -1 // Not found 
 +</code> 
 + 
 +<code> 
 +int index = StrFind(s, "keyword"); 
 +if (index != -1) 
 +    print(s:"Found the keyword at position ", d:index); 
 +else 
 +    print(s:"Keyword not found");
 </code> </code>
  
 +===== See also =====
 +  * [[StrRFind]]
 +  * [[StrFindFrom]]
 +  * [[StrRFindFrom]]
  
functions/strfind.1489996496.txt.gz · Last modified: 2017/03/20 09:54 by korshun