Fandom

Delphi Programming

LeftStr Routine

2,918pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

This page is intended as a supplement to the official documentation on Delphi programming. CodeGear is in the process of putting the Delphi documentation on the Web. Once they have done so, this page will link to the relevant page in the official documentation.
Stub
This article is a stub.
Please help enhance the Delphi Programming Wiki by expanding it.
Info
see the VCL Documentation Guidelines for an overview on doc pages

UnitEdit

DescriptionEdit

function LeftStr(const AText: AnsiString; const ACount: Integer): AnsiString; overload;
function LeftStr(const AText: WideString; const ACount: Integer): WideString; overload;

The LeftStr function takes 2 parameters. The first parameter is the source string and the second is an integer with number of characters from the beginning of the string.

The result is a substring taken from the beginning of the source string with the length in characters given in the second parameter.

Technical CommentsEdit

(Known issues / Documentation clarifications / Things to be aware of)

ExamplesEdit

uses
  StrUtils;
...
var
  SourceString, SubString: String;
  SubStringLength: Integer;
begin
  SourceString := 'Delphi Wikia'; //string length is 12
  SubStringLength := 6;
  SubString := LeftStr(SourceString, SubStringLength);
  ShowMessage(SubString); //will show 'Delphi'

  SubStringLength := 20; //length is more then the source string
  SubString := RightStr(SourceString, SubStringLength);
  ShowMessage(SubString); //will show the complete SourceString 'Delphi Wikia'

  SubStringLength := -1;
  SubString := RightStr(SourceString, SubStringLength);
  ShowMessage(SubString); //If the SubStringLength is anything lower than 1 then then result will be empty
end;

See AlsoEdit

(Please provide links to items specifically related to this item.)

User Comments/TipsEdit

(Please leave your name with your comment.)

Also on Fandom

Random Wiki