如:我想读出从每一行从第5列到第10列的内容,然后showmessage,能读吗?

解决方案 »

  1.   

    给你一段文本编辑的程序!!
    unit Unit1;interfaceuses
        Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
        Dialogs, StdCtrls, ComCtrls;type
        TForm1 = class(TForm)
            RichEdit1: TRichEdit;
            open: TButton;
            save: TButton;
            OpenDialog1: TOpenDialog;
            SaveDialog1: TSaveDialog;
            procedure openClick(Sender: TObject);
            procedure saveClick(Sender: TObject);
        private
        { Private declarations }
        public
        { Public declarations }
        end;var
        Form1: TForm1;
        filename: string;
    implementation{$R *.dfm}procedure TForm1.openClick(Sender: TObject);
    var
        ff: textfile;
        str: string;
    begin
        richedit1.Clear;
        opendialog1.Execute;
        if opendialog1.FileName <> '' then
        begin
            filename := opendialog1.FileName;
            assignfile(ff, filename);
            reset(ff);
            while not Eof(ff) do
            begin
                readln(ff, str);
                richedit1.Lines.Add(str);
            end;
            closefile(ff);
        end;end;procedure TForm1.saveClick(Sender: TObject);
    var
        ff: textfile;
        str: string;
        i: integer;
    begin
        savedialog1.Execute;
        if savedialog1.FileName <> '' then
        begin
            filename := savedialog1.FileName;
            assignfile(ff, filename);
            rewrite(ff);
            for i := 0 to richedit1.Lines.Count do
            begin
                writeln(ff, richedit1.Lines[i]);
            end;
            closefile(ff);
        end;end;end.
      

  2.   

    如果是文本文件,简单的方法是:
    Var
      FList: TStringList;
      tmpStr: String;
    Begin
      FList:= TStringList.Create;
      FList.LoadFromFile(TextFileName);
      IF n < FList.Count Then begin
        tmpStr:= FList.Strings[5] + FList.Strings[6] + ... + FList.Strings[n];
        ShowMessage(tmpStr);
      End;
      FList.Free;
    End;
      

  3.   

    FList.Strings[5] + FList.Strings[6] + ... + FList.Strings[n]读的是那一行的数据?具体表示什么?能解释一下吗?
      

  4.   

    ss:=memo1.lines.string[x];
    sss:=copy(ss,5,5);