Skip to content

StartsStr ​

Another case sensitive function, StartsStr determines whether the substring ASubText begins the string AText.

If ASubText matches the begining of AText, then the result is True, otherwise a False is returned.

For a function that performs the same role but does not take case sensitivity into account, please review the StartsText routine.

Declaration: Function StartsStr(const ASubText, AText : string) : Boolean;

Examples that also use the BoolToStr function are below. Please review BoolToStr for more information.

pascal
procedure OnMapEvent(var Value:Variant);
var
  TheText, FullText, Which : string;
  BoYN : boolean;
begin
  FullText := 'The Archbishop of Canterbury was in attendance.';

  TheText := 'The Archbishop';
  BoYN := StartsStr(TheText, FullText);
  Which := BoolToStr(BoYN, true);
  LogInfo(Which);                        //1st test is true

  TheText := 'The';
  BoYN := StartsStr(TheText, FullText);
  Which := BoolToStr(BoYN, true);
  LogInfo(Which);                        //2nd test is true

  TheText := 'The archbishop';
  BoYN := StartsStr(TheText, FullText);
  Which := BoolToStr(BoYN, true);
  LogInfo(Which);                        //3rd test is false due to case

  TheText := 'An Archbishop';
  BoYN := StartsStr(TheText, FullText);
  Which := BoolToStr(BoYN, true);
  LogInfo(Which);                        //4th test is false due to the word An

end;