【重要求助】vb中如何删除文本里末尾的空行

解决方案 »

  1.   

    是想删除不是绝对空行的空行,如
    123
    2342
    abcd
    最后一个abcd下面的一个默认的空行,其实好像不是空行的这种,想把光标移动到abcd的d这里,请问,跪求
      

  2.   

    Dim s$, ss$(), i%, k%ss = Split(Text1.Text, vbCrLf)
    k = UBound(ss)
    s = "": If ss(k) = "" Then k = k - 1
    For i = 0 To k
        s = s & ss(i)
        If i <> k Then s = s & vbCrLf
    Next
    Text1.Text = s
      

  3.   


    没有看明白,我发现要重新写到print#,貌似最后一行都有空行,文本 ,怎么办呢 
      

  4.   

    用Rtrim("abc")删除字符串末尾的空格
      

  5.   

    用vb内置的open file & print内容方法是肯定不行的,不管你怎么整最后始终都会有一个空行。用fso就可以避免这个问题。Dim fso, tf
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set tf = fso.CreateTextFile("c:\test.txt", True)
    tf.Write "abc" & vbcrlf & "12345"
    tf.Close
      

  6.   


    print #1 "abc" & vbcrlf & "12345";
      

  7.   


    应该是正解,但到最后一个空的时候,如何控制不让有回车呢
    '去掉末尾空行
    Dim fso, tf
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set tf = fso.CreateTextFile("newfile123", True)
        For p = 0 To UBound(tx)
            tf.write tx(p) & vbCrLf
        Next
    tf.Close
      

  8.   

    我整个过程是这么写的,好像不对,
    '【进行文件空格和,号替换处理,空行进行处理]
    N = 0
    Do While Not EOF(1)
        Line Input #1, s
        If s <> "" Then
            ReDim Preserve tx(N)
            s = Replace(s, " ", "")
            s = Replace(s, ",", "|")
            tx(N) = s
            N = N + 1
        End If
    Loop
    Close #1Open "newfile" For Output As #2
        Cls
        For p = 0 To UBound(tx)
            Print #2, tx(p)
        Next
    Close #2
    '去掉末尾空行
    Dim fso, tf
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set tf = fso.CreateTextFile("newfile123", True)
        For p = 0 To UBound(tx)
            tf.write tx(p) & vbCrLf
        Next
    tf.Close
      

  9.   

    我已经搞定了
    '去掉末尾空行
    Dim fso, tf
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set tf = fso.CreateTextFile("newfile", True)
        For p = 0 To UBound(tx)
            If p < UBound(tx) Then
                tf.write tx(p) & vbCrLf
            Else
                tf.write tx(p)
            End If
        Next
    tf.Close
    可能不怎么科学,?请指导
      

  10.   

    要我做的话我就用个字符串将所有数据都拼接起来一起写入。s=s & xxx