StrSearch functionOfficial Content

To allow searching for a string within another one. 


StrSearch( str1 , str2 [, start_char ] );

Type Returned:

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

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

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

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.


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


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


See also

IndexOf Method
StrReplace function

Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.