procedure TForm1.Button1Click(Sender: TObject);
var
sl:TStringList;
i,j:Integer;
tmps:String;
strulen:Integer; //你定义的每列的固定长度
//添加空格
function insspace(str:string;maxspace:Integer):string;
var k:Integer;
begin
str:=trim(str);
for k:=1 to maxspace-Length(str) do
str:=' '+str;
result:=str;
end;
begin
strulen:=8;
sl:=TStringList.Create;
sl.LoadFromFile('d:\My Documents\testtt.txt');
memo2.Lines.Clear;
memo2.Lines.AddStrings(sl);
memo1.Lines.Clear;
for i:=0 to sl.Count-1 do
begin
tmps:='';
for j:=1 to Length(sl[i]) do
if ((j>1) and ((j Mod strulen)=0)) then
begin
if tmps='' then
tmps:=copy(sl[i],j-strulen+1,strulen)
else
tmps:=tmps+','+copy(sl[i],j-strulen+1,strulen);
end;
memo1.Lines.Add(tmps);
end;
sl.Free;
memo3.Lines.Clear;
memo3.Lines.CommaText :=memo1.Lines.Text;
//for i:=0 to memo1.Lines.Count -1 do
// memo3.Lines.AddStrings(memo1.Lines[i].);
for i:=0 to memo3.Lines.Count-1 do
memo3.Lines[i]:=insspace(memo3.Lines[i],strulen);end;
var
sl:TStringList;
i,j:Integer;
tmps:String;
strulen:Integer; //你定义的每列的固定长度
//添加空格
function insspace(str:string;maxspace:Integer):string;
var k:Integer;
begin
str:=trim(str);
for k:=1 to maxspace-Length(str) do
str:=' '+str;
result:=str;
end;
begin
strulen:=8;
sl:=TStringList.Create;
sl.LoadFromFile('d:\My Documents\testtt.txt');
memo2.Lines.Clear;
memo2.Lines.AddStrings(sl);
memo1.Lines.Clear;
for i:=0 to sl.Count-1 do
begin
tmps:='';
for j:=1 to Length(sl[i]) do
if ((j>1) and ((j Mod strulen)=0)) then
begin
if tmps='' then
tmps:=copy(sl[i],j-strulen+1,strulen)
else
tmps:=tmps+','+copy(sl[i],j-strulen+1,strulen);
end;
memo1.Lines.Add(tmps);
end;
sl.Free;
memo3.Lines.Clear;
memo3.Lines.CommaText :=memo1.Lines.Text;
//for i:=0 to memo1.Lines.Count -1 do
// memo3.Lines.AddStrings(memo1.Lines[i].);
for i:=0 to memo3.Lines.Count-1 do
memo3.Lines[i]:=insspace(memo3.Lines[i],strulen);end;
var
sl:TStringList;
begin
sl:=TstringList.Create;
sl.LoadFromFile(C:\test\abc.txt);
memo1.lines.clear;
momo1.lines.addstrings(sl);
memo2.lines.clear;
memo2.lines.add(memo1.lines.strings[1]);
edit1.text:=copy(memo2.lines.strings[0],25,8);
edit1.text:=copy(memo2.lines.strings[0],33,8);
edit1.text:=copy(memo2.lines.strings[0],41,8);
end;可以把3个数分离出来,但只是针对特定的第几行,
如果我希望处理的是有3101和3102的那两行,该咋办啊
用POS('3101',memo1.text)得到的也是绝对的位置吧,不是行的值吧,而且有时莫名其妙的不知道定位到第几行去了另一个想法是用if >0来实现,那如果逐行读取的话,后面可能还有 3101,但我不想读了怎么办,用break吗