unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, StrUtils;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
SI:String;
function GetSL(Source:String):TStringList;
function GetValue(Source:String):String;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SI:='adberdaaegd';
end;
function TForm1.GetSL(Source:String):TStringList;
var i:Integer;
S:String;
SL:TStringList;
begin
SL:=TStringList.Create;
for i:=1 to length(Source) do begin
S:=Source;
if SL.IndexOf(S)=-1 then SL.Add(S);
end;
Result:=SL;
end;
function TForm1.GetValue(Source:String):String;
var SL:TStringList;
i,j,iC:Integer;
S,Str:String;
begin
Str:='';IC:=0;
SL:=GetSL(Source);
for i:=0 to SL.Count-1 do begin
S:=SL;
j:=Length(Source)-Length(StringReplace(Source,S,'',[rfReplaceAll]));
if j>IC then begin
IC:=j;Str:=S;
end;
end;
Result:=Str;
end;
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
begin
s:=GetValue(SI);
showmessage(s);
end;
end.
思路是先获得不重复的字符,然后得到出现次数最大的字符,想要进行其他操作就要自己写一些代码了