MartinLoanel
MartinLoanel

Reputation: 184

How do i check if string exists in Tlist whether its lower or uppercase

I created a function to check if string exits inside Tlist here is my code

function FindDtataLIST(namestring: String): BOOLEAN;
var
  I: Integer;
begin
  Result := False;
  for I := 0 to Listofdata.Count - 1 do
  begin
    if TData(Listofdata.Items[I]).Name = namestring then
    begin
      Result := True;
      Exit;
    end;
  end;
end;

but there is some pitfalls i am stick with , if my listofdata have string with capital letter as example : 'MaRtiN' and name string equal small letter as example : martin result did not return to True i want to check

if FindDtataLIST(namestring) = True whenever if namestring exist with some capital letters or small

Upvotes: 1

Views: 956

Answers (2)

Chr Vel
Chr Vel

Reputation: 1

Use "uppercase"

function FindDtataLIST(namestring: String): BOOLEAN;
var
  I: Integer;
begin
  Result := False;
  for I := 0 to Listofdata.Count - 1 do
  begin
    if uppercase(TData(Listofdata.Items[I]).Name) = uppercase(namestring) then
    begin
      Result := True;
      Exit;
    end;
  end;
end;

Didn't test it, hope this helps...

Upvotes: -2

GabrielF
GabrielF

Reputation: 2121

If you just want to check if both strings are equal, you can use AnsiSameText:

function FindDtataLIST(namestring: String): BOOLEAN;
var
  I: Integer;
begin
  Result := False;
  for I := 0 to Listofdata.Count - 1 do
  begin
    if AnsiSameText(TData(Listofdata.Items[I]).Name, namestring) then
    begin
      Result := True;
      Exit;
    end;
  end;
end;

Upvotes: 6

Related Questions