我的文本文件中数据存储的格式如下:
帧号   标识符   名字   数据
01     000001    ly    12456
请问怎么分别把帧号,标识符,名字和数据放到各自对应的变量中呢?while not Eof(MyText) do
  begin
    Readln(Mytext,Str);
    //分割字符串,付给各个变量????
  end;请帮忙给出例子啊?多谢了!分不够可以再加。

解决方案 »

  1.   

    strTmp := Str;
    for i := 1 to 4 do
    begin
      j := Pos(' '{分割符}, strTmp)
      if (j > 0) then
      begin
        if i = 1 then strIndex: = Copy(strTmp, 1, j - 1);//添加帧号
        if i = 2 then strLabel: = Copy(strTmp, 1, j - 1); //添加标识符
        if i = 3 then strCaption: = Copy(strTmp, 1, j - 1); //添加名称
        if i = 4 then strData: = Copy(strTmp, 1, j - 1); //添加数据
        strTmp := Copy(strTmp, j + 1, Length(TmpStr)); //去掉已经保存的那部分字符
      end;
    end;这段代码是现写的没有经过调试,不过应该没问题
      

  2.   

    j := Pos(' '{分割符}, strTmp)少了个“;”:-)
      

  3.   

    因为记录格式固定,考虑用数据库设计一个DTC,自动把文本文件转成数据库表,
    接下来,就
      

  4.   


    DTC,可以去看看 M$ SQL SERVER 里的包操作这样就可以一劳永逸啦,而且没有什么循环之类的啦