1. Home
  2. Computing & Technology
  3. Delphi Programming

How to split a string into an array

By , About.com Guide

A simple function that accepts a string and a delimiter char, splits a string into tokens (TStringList items) delimited with a char value.

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button1Click(Sender: TObject) ;
var
   A: TStringList;
begin
   A := TStringList.Create;
   try
     Split(' ', 'your delphi guide', A) ;
     ShowMessage(a[0]) ; //your
     ShowMessage(a[1]) ; //delphi
     ShowMessage(a[2]) ; //guide
   finally
     A.Free;
   end;
end;

}
procedure Split
   (const Delimiter: Char;
    Input: string;
    const Strings: TStrings) ;
begin
   Assert(Assigned(Strings)) ;
   Strings.Clear;
   Strings.Delimiter := Delimiter;
   Strings.DelimitedText := Input;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to get DBGrid Cell coordinates
« Adding QuickReports to the Delphi 7 Component Palette

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2002 Delphi Tips
  7. How to split a string into an array

©2009 About.com, a part of The New York Times Company.

All rights reserved.