Friday, 18 November 2011
Home »
Tips and Trick Delphi
» Combine multiple string and then split the string into several substrings based on delimiter in delphi 7
Combine multiple string and then split the string into several substrings based on delimiter in delphi 7
To Share | Friday, 18 November 2011
finally after so long it could be a bit of time to post a tutorial article. this time I'll make a tutorial for combining multiple string or word into a string. And then returns a string that has been split into several substrings join. possible in the merger we will not find a problem too because it is very easy with just a simple script. eg:
String:=''+string1+' '+string2+'';
but what if we want to separate 2 more strings that have been merged for data editing purposes or other purposes? It was a bit troublesome ..
this kind of thing I had just experienced. where usually I just use the DateTimePicker to present the data in the form of date. But yesterday, I was asked to present date in the form of 3 combobox. Just call each with cbhari, cbbulan, and cbtahun. user menginputkan with 3 combobox the last date the data is stored in a field named date (a string merger process) and if a time is needed to edit the data date, the date that had been deposited into a string should be split again into 3 substrings date. that is to day, month and year. example:
user input date: cbday= 7 cbmonth = April cbyears = 1999
then the data is stored into 7/April/1999. and edit if needed, then the string should be split again into 7/April/1999: cbday = 7 cbmonth = April cbyears= 1999
o yes, here used separator / delimiter sign '/' actual ,';', can also use spaces or other signs .
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
ComboBox4: TComboBox;
ComboBox5: TComboBox;
ComboBox6: TComboBox;
Button1: TButton;
Button4: TButton;
Button2: TButton;
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
begin
application.Terminate;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=”+combobox1.Text+’/'+combobox2.Text+’/'+combobox3.Text+”;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
application.terminate;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
s: string;
sl: TStringList;
begin
sl := TStringList.Create;
s := edit1.Text;
sl.Delimiter := ‘/’;
sl.DelimitedText := s;
combobox4.Text:=sl[0];
combobox5.Text:=sl[1];
combobox6.Text:=sl[2];
//ShowMessage(sl[0]);
end;
end.
No comments:
Post a Comment