ObjectPascal
AnsiStartsStr
Function
Returns true if a string starts with a substring StrUtils unit
 function AnsiStartsStr ( const Needle, Haystack : string ) : Boolean;
Description
The AnsiStartsStr function looks for a Needle string at the start of a Haystack string, returning true if it finds it. Otherwise false.
 
It is a Case sensitive command.
Related commands
AnsiContainsStr Returns true if a string contains a substring
AnsiEndsStr Returns true if a string ends with a substring
AnsiContainsText Returns true if a string contains a substring, case insensitive
 
Example code : A simple example
var
  haystack : AnsiString;
begin
  haystack := 'The cat sat on the mat';

  // Note that AnsiStartsStr is case sensitive
  if AnsiStartsStr('THE cat', haystack)
  then WriteLn('''THE cat'' starts the sentence')
  else WriteLn('''THE cat'' does not start the sentence');

  if AnsiStartsStr('The cat', haystack)
  then WriteLn('''The cat'' starts the sentence')
  else WriteLn('''The cat'' does not start the sentence');
end;
Show full unit code
   'THE cat' does not start the sentence
   'The cat' starts the sentence