关于替换文件中不符合规定的回车换行的问题(20分)

  • 主题发起人 主题发起人 wp231957
  • 开始时间 开始时间
W

wp231957

Unregistered / Unconfirmed
GUEST, unregistred user!
//替换回车为空格<br>function replacern(hfile:thandle):dword;<br>const rn:string=#13#10;<br>const sp:string=#20;<br>var<br> &nbsp;readbuffer:string;<br> &nbsp;filesize:integer;<br> &nbsp;numberofbytesrw:dword;<br> &nbsp;i,j,firstrn:integer;<br>begin<br> &nbsp;i:=0;<br> &nbsp;j:=0;<br> &nbsp;firstrn:=0;<br> &nbsp;result:=0;<br> &nbsp;setfilepointer(hfile,0,nil,file_begin);<br> &nbsp;filesize:=getfilesize(hfile,nil);<br> &nbsp;SetLength(readbuffer,2);<br> &nbsp;while i&lt;filesize do begin<br> &nbsp; &nbsp;readfile(hfile,readbuffer[1],sizeof(readbuffer),numberofbytesrw,nil);<br> &nbsp; &nbsp;if (readbuffer[1]=#13) and (readbuffer[2]=#10) then begin<br> &nbsp; &nbsp; &nbsp;result:=i;<br> &nbsp; &nbsp; &nbsp;inc(j);<br> &nbsp; &nbsp; &nbsp;if j=1 then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;firstrn:=i; &nbsp;//记录第一个回车的位置<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;if j&gt;1 then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if ((result-7) mod firstrn)&lt;&gt;0 then begin &nbsp; 如果其他回车位置不符合第一回车的位置,那么就写入空格字符<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writefile(hfile,sp[1],4,numberofbytesrw,nil);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;inc(i,2);<br> &nbsp;end;<br><br>end;
 
//搜索回车的位置<br>function searchrn(hfile:thandle;hfile2:thandle):dword;<br>const rn:string=#13#10;<br>var<br> &nbsp;readbuffer:string;<br> &nbsp;filesize:integer;<br> &nbsp;numberofbytesrw:dword;<br> &nbsp;i:integer;<br>begin<br> &nbsp;i:=0;<br> &nbsp;result:=0;<br> &nbsp;setfilepointer(hfile,0,nil,file_begin);<br> &nbsp;filesize:=getfilesize(hfile,nil);<br> &nbsp;SetLength(readbuffer,4);<br> &nbsp;while i&lt;filesize do begin<br> &nbsp; &nbsp;readfile(hfile,readbuffer[1],sizeof(readbuffer),numberofbytesrw,nil);<br> &nbsp; &nbsp;if (readbuffer[1]=#13) and (readbuffer[2]=#10) then begin<br> &nbsp; &nbsp; &nbsp;result:=i;<br> &nbsp; &nbsp; &nbsp;break;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;inc(i,4);<br> &nbsp;end;<br> &nbsp;if result&lt;&gt;0 then begin<br> &nbsp; &nbsp;setlength(readbuffer,filesize-result-2);<br> &nbsp; &nbsp;setfilepointer(hfile,result+2,nil,file_begin);<br> &nbsp; &nbsp;REAdfile(hfile,readbuffer[1],filesize-result-2,numberofbytesrw,nil);<br> &nbsp; &nbsp;writefile(hfile2,readbuffer[1],filesize-result-2,numberofbytesrw,nil);<br> &nbsp;end;<br>end;<br>//替换回车为空格<br>function replacern(hfile:thandle):dword;<br>const rn:string=#13#10;<br>const sp:string=#20;<br>var<br> &nbsp;readbuffer:string;<br> &nbsp;filesize:integer;<br> &nbsp;numberofbytesrw:dword;<br> &nbsp;i,j,firstrn:integer;<br>begin<br> &nbsp;i:=0;<br> &nbsp;j:=0;<br> &nbsp;firstrn:=0;<br> &nbsp;result:=0;<br> &nbsp;setfilepointer(hfile,0,nil,file_begin);<br> &nbsp;filesize:=getfilesize(hfile,nil);<br> &nbsp;SetLength(readbuffer,2);<br> &nbsp;while i&lt;filesize do begin<br> &nbsp; &nbsp;readfile(hfile,readbuffer[1],sizeof(readbuffer),numberofbytesrw,nil);<br> &nbsp; &nbsp;if (readbuffer[1]=#13) and (readbuffer[2]=#10) then begin<br> &nbsp; &nbsp; &nbsp;result:=i;<br> &nbsp; &nbsp; &nbsp;inc(j);<br> &nbsp; &nbsp; &nbsp;if j=1 then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;firstrn:=i;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;if j&gt;1 then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if ((result-8) mod firstrn)&lt;&gt;0 then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setfilepointer(hfile,-2,nil,file_current);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writefile(hfile,sp[1],4,numberofbytesrw,nil);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setfilepointer(hfile,2,nil,file_current);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;inc(i,2);<br> &nbsp;end;<br><br>end;
 
后退
顶部