写一个txt文件,如果没有额外的行? [英] Writing a .txt file, without a extra line?

查看:100
本文介绍了写一个txt文件,如果没有额外的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公用Sub WriteTextFile(BYVAL SourceToWrite作为字符串,BYVAL LocationToWrite作为字符串)
    昏暗的文件作为System.IO.StreamWriter
    IO.File.Delete(LocationToWrite)
    文件= My.Computer.FileSystem.OpenTextFileWriter(LocationToWrite,真)
    file.WriteLine(SourceToWrite)
    file.Close()
结束小组
 

这是一个模块,我在写一个.txt文件。每次它增加了使用null值的新线。不会真的打扰我,但它增加了,但随后的东西,只有假设有这样3条线路在它结束了5000随着时间的推移,任何人都知道,在写文件怎么不添加额外的行?

解决方案

  file.WriteLine(SourceToWrite)
 

本的WriteLine()函数将一个换行符到它的输出。为了避免这种情况,使用:

  file.Write(SourceToWrite)
 

Public Sub WriteTextFile(ByVal SourceToWrite As String, ByVal LocationToWrite As String)
    Dim file As System.IO.StreamWriter
    IO.File.Delete(LocationToWrite)
    file = My.Computer.FileSystem.OpenTextFileWriter(LocationToWrite, True)
    file.WriteLine(SourceToWrite)
    file.Close()
End Sub

This is a module I made to write to a .txt file. Every time it adds a new line with null value. wouldn't really bother me but it adds but then something that only suppose to have like 3 lines in it ends up with 5000 over time, anyone know how to not add that extra line while writing file?

解决方案

file.WriteLine(SourceToWrite)

The WriteLine() function appends a newline character to its output. To avoid that, use:

file.Write(SourceToWrite)

这篇关于写一个txt文件,如果没有额外的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆