Como verificar uma String
16/12/2003
0
Ex: Str1 = 03 09 15 10 16 26 30 65 95 01
Str2 = 03 09 15 10 16 26 30 65 95 01
Assim é facil
mas e assim
Ex: Str1 = 03 09 15 10 16 26 30 65 95 01
Str2 = 09 15 03 26 10 16 65 01 30 01
ai complica
M@rcio
Posts
16/12/2003
Fórum Vini
você pode usar essa função:
function ehIgual(Str1, Str2: TStringList): boolean; var cont, pos: integer; begin Result:= false; if (Str1.Count <> Str2.Count) then exit; cont:= 0; while (cont <= Str1.Count-1) do begin pos:= Str1.IndexOf(Str2[cont]); if (pos > -1) then begin Str1.Delete(pos); Str2.Delete(cont); cont:= cont-1; end; cont:= cont+1; end; Result:= ((Str2.Count = Str1.Count) and (Str1.Count = 0)); end;
Para chamá-la, faça assim:
var Str1, Str2: TStringList; begin Str1:= TStringList.create; Str2:= TStringList.Create; Str1.Add(´AAA´); Str1.Add(´BBB´); Str1.Add(´CCC´); Str1.Add(´DDD´); Str2.Add(´BBB´); Str2.Add(´CCC´); Str2.Add(´AAA´); Str2.Add(´DDD´); if (ehIgual(Str1, Str2)) then showmessage(´As strings são iguais!´) else showmessage(´As strings são diferentes!´); Str1.Free; Str2.Free; end;
Espero ter ajudado.
Vinicius.
16/12/2003
Renatosilva
Bem, fiz o código abaixo considerando que as strings podem ter caracteres repetidos. Caso deseje strings únicas, responda que eu posto minha função IsUnique, ok? :lol:
--------------------------------------------------------------------------------------
[i:a90889a910][color=darkblue:a90889a910]{ Esta função verifica se duas strings são compostas pelos mesmos caracteres.
É como comparar se uma é igual a outra, mas a ordem dos caracteres não importa.
Ex: 300 = 003 = 030 }[/color:a90889a910][/i:a90889a910]
function StrSameChars(S1, S2: string): Boolean;
var
I: Integer;
begin
Result := False;
if Length(S1) <> Length (S2) then Exit;
if Length(S1) = 0 then Exit;
for I := 1 to Length(S1) do
if Pos(S1[I], S2) = 0 then Exit;
Result := True;
end;
17/12/2003
Beppe
function SameSequence(const S1, S2: String): Boolean; var P1, P2, T1, T2, Z1, Z2: PChar; W: Word; begin Result := S1 = ´´; if Length(S1) = Length(S2) then begin Z1 := StrNew(Pointer(S1)); Z2 := StrNew(Pointer(S2)); try P1 := Z1; T1 := Z1 + Length(S1); T2 := Z2 + Length(S2); repeat P2 := Z2; W := PWord(P1)^; while (P2 < T2) and (W <> PWord(P2)^) do Inc(P2, 3); if P2 >= T2 then Exit; PWord(P2)^ := 0; Inc(P1, 3); until P1 >= T1; Result := True; finally StrDispose(Z1); StrDispose(Z2); end; end; end;
Isto poderia ser generalizado, mas perderia sua eficiência. Como não há checagens, o ´número inteiro´ pode ser formado por qualquer sequência de caracteres, não apenas dígitos.
22/07/2010
Abraão Monteiro
SE HASH_MD5(String1) IGUAL HASH_MD5(String2) ENTÃO
// Execute algo
O MD5 é utilizado para fazer checksum.
Att,
Abraão
Clique aqui para fazer login e interagir na Comunidade :)