Returns true if a string starts with a substring StrUtils unit
 function AnsiStartsStr(const Needle, Haystack string):Boolean;
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
AnsiContainsStrReturns true if a string contains a substring
AnsiEndsStrReturns true if a string ends with a substring
AnsiContainsTextReturns true if a string contains a substring, case insensitive
 Download this web site as a Windows program.

Example code : A simple example
  haystack : AnsiString;
  haystack := 'The cat sat on the mat';

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

  if AnsiStartsStr('The cat', haystack)
  then ShowMessage('''The cat'' starts the sentence')
  else ShowMessage('''The cat'' does not start the sentence');
Show full unit code
  'THE cat' does not start the sentence
  'The cat' starts the sentence
Delphi Programming © Neil Moffatt 2002 - 2022. All rights reserved.  |  Home Page