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 use PHP Alike implode & explode functions for Delphi 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
23-Jun-03
Category
Algorithm
Language
Delphi 6.x
Views
166
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Ronald Buster

Implode & Explode routines just for Dephi making life easy ...

Answer:
1   
2   //////////////////////////////////////////////////////////////////////////
3   // Procedure - implode
4   // Author    - Ronald Buster
5   // Remarc    - PHP like implode function
6   //
7   // Returns a string containing a string representation of all the array
8   // elements in the same order, with the glue string between each element.
9   //////////////////////////////////////////////////////////////////////////
10  
11  function implode(const glue: string; const pieces: array of string): string;
12  var
13    I: Integer;
14  begin
15    Result := '';
16    for I := 0 to High(Pieces) do
17      Result := Result + Glue + Pieces[I];
18    Delete(Result, 1, Length(Glue));
19  end;
20  
21  //////////////////////////////////////////////////////////////////////////
22  // Procedure - explode
23  // Author    - Ronald Buster
24  // Remarc    - PHP like explode function
25  //
26  // Returns an array of strings, each of which is a substring of string
27  // formed by splitting it on boundaries formed by the string separator.
28  // If limit is set, the returned array will contain a maximum of limit
29  // elements with the last element containing the rest of string.
30  //
31  //////////////////////////////////////////////////////////////////////////
32  
33  function explode(const separator, s: string; limit: Integer = 0): TDynStringArray;
34  var
35    SepLen: Integer;
36    F, P: PChar;
37  begin
38    SetLength(Result, 0);
39    if (S = '') or (Limit < 0) then
40      Exit;
41    if Separator = '' then
42    begin
43      SetLength(Result, 1);
44      Result[0] := S;
45      Exit;
46    end;
47    SepLen := Length(Separator);
48  
49    P := PChar(S);
50    while P^ <> #0 do
51    begin
52      F := P;
53      P := AnsiStrPos(P, PChar(Separator));
54      if (P = nil) or ((Limit > 0) and (Length(Result) = Limit - 1)) then
55        P := StrEnd(F);
56      SetLength(Result, Length(Result) + 1);
57      SetString(Result[High(Result)], F, P - F);
58      F := P;
59      while (P^ <> #0) and (P - F < SepLen) do
60        Inc(P);
61    end;
62  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