Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
how to Implode / Explode methods like in PHP Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
22-Feb-03
Category
Object Pascal-Strings
Language
Delphi All Versions
Views
137
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: David Johannes Rieger

In Delphi you can also use the implode and explode methods from PHP:

Answer:

1   type
2     TDynStringArray = array of string;
3   
4   function Implode(const Glue: string; const Pieces: array of string): string;
5   var
6     I: Integer;
7   begin
8     Result := '';
9     for I := 0 to High(Pieces) do
10      Result := Result + Glue + Pieces[I];
11    Delete(Result, 1, Length(Glue));
12  end;
13  
14  function Explode(const Separator, S: string; Limit: Integer = 0): TDynStringArray;
15  var
16    SepLen: Integer;
17    F, P: PChar;
18  begin
19    SetLength(Result, 0);
20    if (S = '') or (Limit < 0) then
21      Exit;
22    if Separator = '' then
23    begin
24      SetLength(Result, 1);
25      Result[0] := S;
26      Exit;
27    end;
28    SepLen := Length(Separator);
29  
30    P := PChar(S);
31    while P^ <> #0 do
32    begin
33      F := P;
34      P := AnsiStrPos(P, PChar(Separator));
35      if (P = nil) or ((Limit > 0) and (Length(Result) = Limit - 1)) then
36        P := StrEnd(F);
37      SetLength(Result, Length(Result) + 1);
38      SetString(Result[High(Result)], F, P - F);
39      F := P;
40      while (P^ <> #0) and (P - F < SepLen) do
41        Inc(P); // nächsten Anfang ermitteln
42    end;
43  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC