得到字符串listbox内数据出现的次数。Yulo
yulo
yulo
总共出现了三次,
能不能得出结果超过了1次,不区分大小可以吗?

解决方案 »

  1.   

    能,但是需要你自己做程序去处理
    procedure TForm1.Button3Click(Sender: TObject);
    var
      Tmp: TStringList;
      i, n: Integer;
    begin
      Tmp := TStringList.Create;
      try
        Tmp.CaseSensitive := False;  //不区分大小写
        for i := 0 to ListBox1.Items.Count - 1 do
        begin
          n := Tmp.IndexOfName(ListBox1.Items[i]);
          if n = -1 then
            Tmp.Add(ListBox1.Items[i] + '=1')
          else
            Tmp[n] := Tmp.Names[n] + '=' + IntToStr(StrToInt(Tmp.ValueFromIndex[n]) + 1);
        end;
        Memo1.Clear;
        Memo1.Lines.AddStrings(Tmp);
      finally
        Tmp.Free;
      end;
    end;上面的代码效率不是很高,但是能完成你要求的任务
      

  2.   

    SysUtils.CompareText就是不区分大小写的比较