如何删除写入文本中的回车换行

[复制链接]
查看11 | 回复2 | 2008-11-5 16:57:52 | 显示全部楼层 |阅读模式
是一个vba的程序,粘一点代码吧

Open DPath + "a1.txt" For Output As #1

Print #1, Total

Close #1
在total中含有chr(10)和chr(13),所以在写入到文本文件后在最后的两行是空行,是回车和换行,如何去掉,谢谢大家!
谢谢jinselianren 的答案,不过用goto语句处理以后会把全部数据都删除掉,因为每一行后面都会有chr(10)和chr(13),right函数会逐行判断的 ,大家帮忙看看还有什么好的办法吗?

回复

使用道具 举报

千问 | 2008-11-5 16:57:52 | 显示全部楼层
Open DPath + "a1.txt" For Output As #1 Print #1, replace(replace(Total,chr(13),""),chr(10),"") Close #1 上面那个太麻烦了,如果存在多个还会出错,我这个不会 嘿嘿jc:if right(total,1)=chr(10) or right(total,1)=chr(13) thentotal=mid(1,len(toral)-1)goto jcend if只处理最后有回车或者换行的...
回复

使用道具 举报

千问 | 2008-11-5 16:57:52 | 显示全部楼层
tempstr=totalfor i=1 to len(tempstr) if mid(tempstr,i,1)chr(10) or mid(tempstr,i,1)chr(10) then
total=total & mid(tempstr,i,1) end ifnextOpen DPath + "a1.txt" ...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行