有类似如下一字符串:“2:牛 4:鸡 1:猪 3:虎 8:猴 3:马”如何实现按生肖前面的数值从大小到的顺序排列,即得到如下字串:“8:猴 4:鸡 3:虎 3:马 2:牛 1:猪”
解决方案 »
- delphi怎样用ADOquery连接SQL数据库
- 好怪的問題
- TABLE关闭速度问题?
- 求S:='ABCD$EF/1G3H4/I323J/K43L/M4N%7O8P$9QR$STUV'中各字符所对应ASC值的和,但不包括$和/
- 紧急求救:怎样通过汉字编码获得汉字的声母
- 请问在ACCESS的查询中,有没有标准差的计算公式的?
- 為什么在主從表中用ADO連接SQL Server時﹐動態地指定ADOConnection的connectionstring時卻總是出現這種錯誤﹗
- 请问delphi的论坛比较好的都有哪些!
- 如何在DELPHI中用最新版本的ADO??
- 怎么能保存LISTBOX按件的数据到我指定的数据文件中!
- 初学请教一下,怎么运行记事本
- 哪位有没有reportbuilder的教程?共享一下。万分感谢!
function mycomp(List: TStringList; Index1, Index2: Integer): Integer;
var
p,n1,n2:integer;
s:string;
begin
p:=pos(':',list.Strings[index1]);
n1:=StrToInt(copy(list.Strings[index1],1,p-1));
p:=pos(':',list.Strings[index2]);
n2:=StrToInt(copy(list.Strings[index2],1,p-1));
result:=n1-n2;
end;procedure TForm1.Button1Click(Sender: TObject);
var
t:tstringlist;
begin
t:=tstringlist.Create;
t.Add('1:aweqw');
t.Add('2:asd');
t.Add('4:adas');
t.Add('11:asdasd');
t.Add('15:ewr');
t.Add('10:sdfsdf');
t.Add('20:sfsd');
t.CustomSort(mycomp);
Memo1.Lines.AddStrings(t);
end;
I : Integer ;
s : string;
p : pchar;
StringList : TstringList;
p1 : pchar;
begin
StringList := Tstringlist.create();
s := '2:牛 4:鸡 1:猪 3:虎 8:猴 3:马';
p := @s[1];
p1 := p;
while p^ <> #0 do
begin
if p^ = char(' ') then
begin
p^ := char(0);
Stringlist.add(strpas(p1));
inc(p);
p1 := p;
end;
inc(p);
end;
StringList.sort;
for I := 0 to StringList.Count - 1 do // Iterate
begin
showmessage(Stringlist.Strings[i]) ;
end ; // for
StringList.free;