StrPas

0

skad wziac funckeje StrPas (modul SysUtuls???)p
potrzebuje tej funkcji w pascalu.

0

Jeden ze sposobow:

function StrPas(const Str: PChar): string;
var
  i: Integer;
  pom: string;
begin
  i := 0;
  while Str[i]<>Chr(0) do
    pom := pom + Str[i];
end;

Swoja droga strasznie powolny i brzydki, ale nie chce mi sie pisac niczego ladniejszego. Najpiekniej to by w asm wygladalo :) (zwlaszcza, jezeli string byloby typowo pascalowe)

0

v1:

function StrPas(const Str: PChar): string;
var
  i: byte;
  pom: string;
begin
  i := 0;
  while (Str[i] <> #0) and (i < 255) do 
  begin
    pom[i+1] := Str[i];
    inc(i);
  end;

  pom[0] := char(i);

  StrPas := pom;
end;

v2:

function StrPas(const Str: PChar): string;
var
  pom: string;
begin
  pom[0] := #0;
  while (Str[byte(pom[0])+1] <> #0) and (pom[0] <> #255) do inc(pom[0]);
  move(Str,pom[1],byte(pom[0]));

  StrPas := pom;
end;
0

Ah, skoro az dwie zostaly podane, to nie odpuszcze jak nie naszkicuje mojej ulubionej:

lea     di, Str
mov     cx, -1
xor     al, al
cld
repne   scasb
not     cx
dec     cx
mov     byte Str, cl
dec     di
mov     si, di
dec     di
rep     movsb

W FASM, ale nie moglem sobie odpuscic :P

1 użytkowników online, w tym zalogowanych: 0, gości: 1