Official Content

Searches for a string within another one. 


StrSearch( str1 , str2 [, start_char ] );

    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.

Type Returned:


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)


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

See Also

IndexOf method
StrReplace function

Last update: November 2023 | © GeneXus. All rights reserved. GeneXus Powered by Globant