vb 大侠们 判断一个txt文件每一行是否有制表符,没有的在该行后面添加一个制表符 怎么写呢? 谢谢啊

2025-02-25 21:59:25
推荐回答(1个)
回答1:

Private Sub Command1_Click()
    Dim col As New Collection ’定义集合对象
    Open "c:\you.txt" For Input As #1 ’假如文件"c:\you.txt"
    Dim strLine
    Do Until EOF(1) '读取文件
        Line Input #1, strLine
        If InStr(strLine, vbTab) > 0 Then '判断是否有Tab符
            col.Add strLine
        Else
            col.Add strLine & vbTab
        End If
    Loop
    Close #1
    Open "c:\you.txt" For Output As #1
    For Each strLine In col ‘写入文件
        Print #1, strLine
    Next
    Close #1
End Sub