vb 怎样去除文件里空行

ajunajun 2009-02-18 10:14:48
一行一行的读文件,可怎样去除空行呢?
...全文
193 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
白发程序猿 2009-02-19
  • 打赏
  • 举报
回复
这么多星级专家回复了
我就来顶顶好了
of123 2009-02-19
  • 打赏
  • 举报
回复

判断一下,去除所有空行。读到 EOF 后补一个空行。
SYSSZ 2009-02-19
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim nextline, b, c As String
Dim i, j, k, l As Integer
Open "c:\01.txt" For Input As #1
b = ""
i = 0
Do Until EOF(1)
Line Input #1, nextline
i = i + 1
If Trim(nextline) <> "" Then
b = b & nextline & vbCrLf
j = i
End If
Loop
Close #1
k = i - j
Select Case k
Case 0
b = Left(b, Len(b) - 2)
Case Is > 0
Do Until k - l = 0
c = c & vbCrLf
l = l + 1
Loop
b = Left(b, Len(b) - 2) & c
End Select
Open "c:\02.txt" For Output As #2
Print #2, b
Close #2
Kill "c:\01.txt"
Name "c:\02.txt" As "c:\01.txt"
End Sub
goosen 2009-02-18
  • 打赏
  • 举报
回复
什么意思啊...
你贴一段你的数据

12255 25545
ddff 256 225
是这样的数据吗
ajunajun 2009-02-18
  • 打赏
  • 举报
回复
补充:只去除中间的空行,末尾的空行不去除
goosen 2009-02-18
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim strTemp As String
Open "c:\1.txt" For Input As #1
Open "c:\strFile.txt" For Output As #2
While (Not EOF(1))
Line Input #1, strTemp
If Mid(Trim(strTemp), 1, 1) <> "" Then Print #2, strTemp
Wend
Close #1
Close #2
MsgBox "你的数据已保存到c:\strFile.txt中"
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧