我如何检查字符串是否存在于 Tlist 中,无论是小写还是大写

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

我创建了一个函数来检查字符串是否存在于 Tlist 中,这是我的代码

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;

但是我仍然坚持一些陷阱,如果我的 listofdata 有大写字母的字符串作为示例:'MaRtiN' 并且名称字符串等于小写字母作为示例:martin 结果没有 return 到 True 我想检查

if FindDtataLIST(namestring) = True 每当 namestring 存在一些大写字母或小写

如果你只想检查两个字符串是否相等,你可以使用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;

使用"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;

没测试过,希望对你有帮助...