是一个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函数会逐行判断的 ,大家帮忙看看还有什么好的办法吗?
如何删除写入文本中的回车换行
答案:3 悬赏:60 手机版
解决时间 2021-03-23 18:48
- 提问者网友:低吟詩仙的傷
- 2021-03-22 18:15
最佳答案
- 五星知识达人网友:一秋
- 2021-03-22 19:38
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) then
total=mid(1,len(toral)-1)
goto jc
end if
只处理最后有回车或者换行的
Print #1, replace(replace(Total,chr(13),""),chr(10),"")
Close #1
上面那个太麻烦了,如果存在多个还会出错,我这个不会 嘿嘿
jc:
if right(total,1)=chr(10) or right(total,1)=chr(13) then
total=mid(1,len(toral)-1)
goto jc
end if
只处理最后有回车或者换行的
全部回答
- 1楼网友:人類模型
- 2021-03-22 20:31
tempstr=total
for 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 if
next
Open DPath + "a1.txt" For Output As #1
Print #1, Total
Close #1
- 2楼网友:千夜
- 2021-03-22 20:20
1 在打开文件的时候,使用可写的方式,包括 "a" "a+" "w" "w+" "r+"等。 2 获取到合法的文件指针fp后,在需要的地方使用写入函数,输入回车。以下几种方式均可达到效果: 1) fputs("",fp); fputs是写入一行字符串,并加换行。所以在输入空串的时...
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯