Arsip: Perintah Explode

 
user image
more 14 years ago

Yudho

Mas Mbak saya mau nanya. Perintah explode/implode(PHP) ada nggak ya di delphi?
user image
more 14 years ago

Manz

aku dapet guugling nih ... :D Sample 1:

type
  TStrArray = array of string;
function Explode(var a: TStrArray; Border, S: string): Integer;
var
  S2: string;
begin
  Result  := 0;
  S2 := S + Border;
  repeat
    SetLength(A, Length(A) + 1);
    a[Result] := Copy(S2, 0,Pos(Border, S2) - 1);
    Delete(S2, 1,Length(a[Result] + Border));
    Inc(Result);
  until S2 = '';
end;
// How to use it:
procedure TForm1.Button1Click(Sender: TObject);
var
  S: string;
  A: TStrArray;
  AnzTokens, i: Integer;
begin
  S := 'Ein=Text=durch=Geleichzeichen=getrennt';
  AnzTokens := Explode(A, '=', S);
  for i := 0 to AnzTokens -1 do
    Memo1.Lines.Add(A[i]);
end;
// 2. ...............................................
{
   These 2 functions are from the programming language PHP, unite certainly well-known.
    Now one can use it also in Delphi:)
   Diese 2 Funktionen sind aus der Programmiersprache PHP, einigen bestimmt bekannt.
    Nun kann man sie auch in Delphi verwenden :)
}
{...}
//* Needed type declaration
type
  TExplodeArray = array of String;
{...}
function Implode(const cSeparator: String; const cArray: TExplodeArray): String;
var
  i: Integer;
begin
  Result := '';
  for i := 0 to Length(cArray) -1 do begin
    Result := Result + cSeparator + cArray[i];
  end;
  System.Delete(Result, 1, Length(cSeparator));
end;
function Explode(const cSeparator, vString: String): TExplodeArray;
var
  i: Integer;
  S: String;
begin
  S := vString;
  SetLength(Result, 0);
  i := 0;
  while Pos(cSeparator, S) > 0 do begin
    SetLength(Result, Length(Result) +1);
    Result[i] := Copy(S, 1, Pos(cSeparator, S) -1);
    Inc(i);
    S := Copy(S, Pos(cSeparator, S) + Length(cSeparator), Length(S));
  end;
  SetLength(Result, Length(Result) +1);
  Result[i] := Copy(S, 1, Length(S));
end;
Sample 2:

function implode(const glue: string; const pieces: array of string): string; 
var I: Integer; 
begin 
  Result := ''; 
  for I := 0 to High(Pieces) do 
    Result := Result + Glue + Pieces[I]; 
  Delete(Result, 1, Length(Glue)); 
end; 

function explode(const separator, s: string; limit: Integer = 0): TDynStringArray; 
var SepLen: Integer; 
    F, P: PChar; 
begin 
  SetLength(Result, 0); 
  if (S = '') or (Limit < 0) then 
    Exit; 
  if Separator = '' then 
    begin 
      SetLength(Result, 1); 
      Result[0] := S; 
      Exit; 
    end; 
  SepLen := Length(Separator); 
  P := PChar(S); 
  while P^ <>#0do 
    begin 
      F := P; 
      P := AnsiStrPos(P, PChar(Separator)); 
      if (P = nil) or ((Limit > 0) and (Length(Result) = Limit - 1)) then 
        P := StrEnd(F); 
      SetLength(Result, Length(Result) + 1); 
      SetString(Result[High(Result)], F, P - F); 
      F := P; 
      while (P^ <>#0)and (P - F < SepLen) do 
        Inc(P); 
    end; 
end;
tapi belon dicobain, silahkan yang mana yang suitable dengan anda .... itu tadi sourcenya dari mbah google :lol:
user image
more 14 years ago

sandyQx

wah mas aku juga mau naya nih gimana cara nampilin record dari tabel mysql kedalam sebuah combo bbox
user image
more 14 years ago

Manz

loop until eof begin combobox1.additem "isi recordnya apa yang mau ditampilkan" end :D
user image
more 14 years ago

imunk

waduh aku malah bingung apaan tuh explod dan implod.. minta penjelesannya dong mas, biar aku tambah ilmu.. mau pintar memang harus susah dulu.
user image
more 14 years ago

Manz

hihihi explode artinya menguraikan string berdasarkan string tertentu. contoh explode(tgl, "-"), jadi tgl misal 09-10-2006 jadinya tgl[1] : 09, tgl[2]: 10, tgl[3]: 2006. kalo implode kebalikannya.
more ...
  • Pages:
  • 1
Share to
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com