StrSearch function

Official Content
This documentation is valid for:

Searches for a string within another one. 

Syntax

StrSearch( str1 , str2 [, start_char ] );

Where:
str1
    String on which the search will be done. It may be of the Character data type, VarChar data type or LongVarChar data type.

str2
    Search string. It may be of the Char, Varchar or Long varchar type.

Start_char
    Optional. It indicates the search start position. This variable is of the positive number type.

Type Returned:
Numeric

Scope

Objects: Procedure, Transaction, Web Panel, Work Panel
Generators: .NET, Ruby (up to GeneXus X Evolution 3), Java, Visual FoxPro (up to GeneXus X Evolution 3)

Description

StrSearch returns the position (integer index starting at 1) of the Str1 string where the Str2 string was found. It searches from front to back. The starting position in the search is optional. If it is omitted, then the starting position is the position 1 of the Str1 string.

  • The Start_Char parameter is a positive number and indicates the initial position of the search within the Str1.  If it is 0, then the function return to 0.
  • The comparison between characters is case-sensitive; i.e.:  'a' is different from 'A'.
  • If Str1 is empty or the length is shorter than Str2, then the function returns 0, since the search cannot be carried out.
  • If Str2 is empty, it returns Start_Char if it was initialized. Otherwise, it returns 1.

Samples

&str1 ="StrSearch function tests"
StrSearch(&str1,"j")       // returns  0 (not found)  
StrSearch(&str1,"a" )      // returns  6
StrSearch(&str1, "e" , 7)  // returns 21

See Also

IndexOf method
StrReplace function