Split string in Delphi

Source: Internet
Author: User

There is no function like string. Split (C # does have) in Delphi.

So if you need to split a string, you can use tstringlist to finish this work.

With the code bellow, We can does split a string with a char.

   1:  function Split(aStrInput: string; aChrDelimiter: char): array of string;
   2:  var
   3:     lstSplit: TStringList;   
   4:     arrResult: array of string;
   5:  begin
   6:     lstSplit := TStringList.Create;
   7:     SetLength(arrResult, 3);
   8:     lstSplit.Delimiter := ':';
   9:     lstSplit.DelimitedText := aStrInput;
  10:     arrResult[0] := lstSplit.Strings[0];
  11:     arrResult[1] := lstSplit.Strings[1];
  12:     arrResult[2] := lstSplit.Strings[2];

13: Result := arrResult;

14: FreeAndNil(lstSplit);

  15:  end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.