【问题标题】:alternative to encode file to ascii将文件编码为 ascii 的替代方法
【发布时间】:2012-10-24 05:46:35
【问题描述】:

我试图找到将 UTF-8 编码为 ASCII 的替代方法。以下方法有效,但将这个 486kb 文件编码为 ASCII 需要 1 分 40 秒

For Each foundFile As String In My.Computer.FileSystem.ReadAllText(My.Settings.TempFile)
        foundFile = foundFile
        My.Computer.FileSystem.WriteAllText(My.Settings.DefaultOutput, foundFile, True, System.Text.Encoding.ASCII)
    Next

如果有人能告诉我比上述方法更快的方法,我将不胜感激。

谢谢

【问题讨论】:

    标签: vb.net ascii encode fso


    【解决方案1】:

    ReadAllText 返回一个简单的String,因此您正在循环遍历该字符串中的每个字符,这会很慢。

    相反,只是做

    Dim fileText As String = My.Computer.FileSystem.ReadAllText(My.Settings.TempFile)
    My.Computer.FileSystem.WriteAllText(My.Settings.DefaultOutput, fileText, True, System.Text.Encoding.ASCII)
    

    【讨论】:

    • 感谢 nneonneo,您的方法提供了比以前更快的方法(低于 10 秒)。再次感谢您的回答。我非常感谢它。
    猜你喜欢
    • 2017-05-26
    • 2011-10-07
    • 2010-10-17
    • 2020-05-25
    • 1970-01-01
    • 1970-01-01
    • 2013-02-28
    • 1970-01-01
    • 2011-02-03
    相关资源
    最近更新 更多