Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Для новичков > trim string help needed


Автор: huismori 3.3.2010, 16:54
i want to trim the string from registry... i get the line from registry as  221.192.132.194:80  and i want to trim it to edit objects such as

Цитата

edit1.text (221)
edit2.text (192)
edit3.text (132)
edit4.text (194)
edit5.text (80)


i can get it as a single string but i want to put them in different edit objects... thats what i use for single string...

Код

var
Reg1:TRegistry;
Text:string;
begin
Reg1:=TRegistry.Create;
Reg1.RootKey:=HKEY_CURRENT_USER;
Reg1.OpenKey('Software\Microsoft\Windows\CurrentVersion\Internet Settings',true);
Text:=Reg1.ReadString('Proxyserver');
Reg1.CloseKey;
Reg1.Free;
Edit1.Text:=Text;


can someone please help me to trim it ?

Автор: former 3.3.2010, 17:14
Use http://www.regular-expressions.info/.

Автор: huismori 3.3.2010, 17:23
thanks for the link but does it actually have anything to do with delphi ? i didnt understand it

Автор: muratboy31 3.3.2010, 18:46
try something like that

Код

procedure TForm1.Button1Click(Sender: TObject);
var
   A: TStringList;
begin
   A := TStringList.Create;
   try
     Split(' ', '212.224.195.258:80', A) ;
     Edit1.Text:= a[0];
     Edit2.Text:= a[1];
     Edit3.Text:= a[2];
     Edit4.Text:= a[3];
     Edit5.Text:= a[4];    
   finally
     A.Free;
   end;
end;

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

Автор: huismori 3.3.2010, 22:12
this works but it doesnt seperate after ':' it includes it to last string... i want to split 80 to another edit...

Код

procedure TForm1.Button1Click(Sender: TObject);
var
   A: TStringList;
begin
   A := TStringList.Create;
   try
     Split('.', '212.224.195.258:80', A) ;
     Edit1.Text:= a[0];
     Edit2.Text:= a[1];
     Edit3.Text:= a[2];
     Edit4.Text:= a[3];
     Edit5.Text:= a[4];    
   finally
     A.Free;
   end;
end;

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

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)