00/xx
00/11
00/ee
00/111
00/3241234
cn/www
cn/sdsfd
cn/wssf
tt/werw
tt/qeqw
tt/sdfsf如题,如果我想要让它把cn开头的放到顶头,或得到cn所在的位置,请怎么做?
00/11
00/ee
00/111
00/3241234
cn/www
cn/sdsfd
cn/wssf
tt/werw
tt/qeqw
tt/sdfsf如题,如果我想要让它把cn开头的放到顶头,或得到cn所在的位置,请怎么做?
然后定义一个排序规则,慢点就用冒泡吧
不知道你要怎么排
排完再写回memo里面
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
J: Integer;
begin
J := 0;
with Memo1.Lines do
begin
BeginUpdate;
try
for I := 0 to Count - 1 do
if Pos('cn', Memo1.Lines[I]) = 1 then
begin
Memo1.Lines.Move(I, J);
Inc(J);
end;
finally
EndUpdate;
end;
end;
end;
TSortList = class(TStringList)
protected
function CompareStrings(const S1, S2: string): Integer; override;
end;function TSortList.CompareStrings(const S1, S2: string): Integer;
var
ss1,ss2: string;
begin
ss1 := copy(S1,1,2); ss2 := copy(S2,1,2);
if (ss1='cn') and (ss2<>'cn') then result := 1;
if (ss1='cn') and (ss2='cn') then result := 0;
if (ss1<>'cn') and (ss2='cn') then result := -1;
if (ss1<>'cn') and (ss2<>'cn') then result :=0;
end;var
TmpList: TSortList;
begin
TmpList := TSortList.create;
TmpList.Assign(Memo1.Lines);
TmpList.Sort;
Memo1.Lines.Assign(TmpList);
TmpList.Free;
end;上面的方法很灵活,可以随意修改排序规则
end;