1. procedure TForm1.Button1Click(Sender: TObject); function Sort(const AStr: string): string; var i, j: Integer; str, s: string; begin str := AStr; for i := 1 to Length(str) do begin s := str[i]; for j := i to Length(str) do if s > str[j] then begin str[i] := str[j]; str[j] := s[1]; s := str[i]; end; Result := str; end; end; function GetReptStr(const AStr: string): string; var i: Integer; s: string; begin for i := 1 to Length(AStr) - 1 do begin s := AStr[i]; if s = AStr[i + 1] then if Pos(s, Result) = 0 then Result := Result + s; end; end;const str = '2354662224'; begin Edit1.Text := Sort(str); Edit2.Text := GetReptStr(Sort(str)); end;
2. procedure TForm1.Button2Click(Sender: TObject); const stra = '2354489'; strb = '3265247'; var i: Integer; s: string; begin for i := 1 to Length(stra) do if Pos(stra[i], strb) > 0 then s := s + stra[i]; Edit1.Text := s; end; 然后再对所得的字符串执行1的方法;写的有些邋遢,哈哈,权做参考
这样排序,可以少写几行代码 :b function SortStr(const AStr: string): string; var sl: TStringList; i: Integer; begin sl := TStringList.Create; for i := 1 to Length(AStr) do sl.Append(AStr[i]); sl.Sort; for i := 0 to sl.Count - 1 do Result := Result + sl.Strings[i]; sl.Free; end;
procedure TForm1.Button1Click(Sender: TObject);
function Sort(const AStr: string): string;
var
i, j: Integer;
str, s: string;
begin
str := AStr;
for i := 1 to Length(str) do
begin
s := str[i];
for j := i to Length(str) do
if s > str[j] then
begin
str[i] := str[j];
str[j] := s[1];
s := str[i];
end;
Result := str;
end;
end; function GetReptStr(const AStr: string): string;
var
i: Integer;
s: string;
begin
for i := 1 to Length(AStr) - 1 do
begin
s := AStr[i];
if s = AStr[i + 1] then
if Pos(s, Result) = 0 then Result := Result + s;
end;
end;const str = '2354662224';
begin
Edit1.Text := Sort(str);
Edit2.Text := GetReptStr(Sort(str));
end;
procedure TForm1.Button2Click(Sender: TObject);
const stra = '2354489'; strb = '3265247';
var
i: Integer;
s: string;
begin
for i := 1 to Length(stra) do
if Pos(stra[i], strb) > 0 then
s := s + stra[i];
Edit1.Text := s;
end;
然后再对所得的字符串执行1的方法;写的有些邋遢,哈哈,权做参考
function SortStr(const AStr: string): string;
var
sl: TStringList;
i: Integer;
begin
sl := TStringList.Create;
for i := 1 to Length(AStr) do
sl.Append(AStr[i]);
sl.Sort;
for i := 0 to sl.Count - 1 do
Result := Result + sl.Strings[i];
sl.Free;
end;
第二个有问题呀