Mega Code Archive

 
Categories / Delphi / Functions
 

Split function (like in VB)

Title: Split function (like in VB) Question: How to split string? Simply... Answer: Split function like in VisualBasic ===CODE STARTS HERE=== //* Part of VBFunctions.pas *// //* (c) VLaD 2001 :-] *// unit VBFunctions; Interface Uses SysUtils; function VBSplit( Delimiter:string; TextString:string; Index:integer ) : string; implementation function VBSplit( Delimiter:string; TextString:string; Index:integer ) : string; var i, ldelimiter,search: integer; s: string; begin i := 0; s := TextString; search := pos(Delimiter,s); LDelimiter := Length(Delimiter); if search = 0 then begin result := ''; exit; end; if Index = 0 then begin s := copy(s,1,search-1); result:=s; exit; end else while i begin search := pos(Delimiter,s); s := copy(s,search+LDelimiter,MaxInt); i := i +1; end; search := pos(Delimiter,s); if search 0 then s := copy(s,1,search -1); Result := s; end; ===CODE ENDS HERE=== ===EXAMPLE ON HOW TO USE=== Example on how to use it: procedure TForm1.Button1Click(Sender: TObject); var pproxy : string; begin pproxy := '192.168.1.3:80'; messagebox(0,PChar(VBSplit(':',pproxy,0)),'Proxy Host',0); messagebox(0,PChar(VBSplit(':',pproxy,1)),'Proxy Port',0); end; ========================== Sorry for *lame* code, but im begginer :() (if any errors/bugs please send reply)