我已经将一个文本文件(名称)读入数组,我需要如何将这些名称按字母顺序排序,并在丰富的编辑中显示这些名称?
请给我从这一点开始的代码:
readln(myfile,arri);
‘'myfile’是文本文件,'arr‘是字符串数组。另外,我声明了'i‘为一个整数,尽管它是一个字符串数组。这样可以吗?
发布于 2010-05-18 21:15:39
使用排序而不是数组,并将TStringList属性设置为true。
var
sortlist : TStringList; // Define our string list variable
begin
// Define a string list object, and point our variable at it
sortlist := TStringList.Create;
try
// Now add some names to our list
sortlist.Sorted := True;
// And now find Brian's age
sortlist.LoadFromFile(myfile);
// Do something.
finally
// Free up the list object
sortlist.Free;
end;
end;
发布于 2010-05-18 21:15:36
使用StringList就很容易了。StringList还可以自动排序。在这里看一个例子(向下滚动):http://www.delphibasics.co.uk/Article.asp?Name=Files
https://stackoverflow.com/questions/2861171
复制