Question

i trying to find alternative method to encode UTF-8 to ASCII. Below method works but it takes 1 minutes and 40 second to encode this 486kb file to ASCII

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

if anyone can show me a fastest way than above method, i greatly appreciated.

Thanks

Was it helpful?

Solution

ReadAllText returns a simple String, so what you are doing is looping over every single character in that string, which will be slow.

Instead, just do

Dim fileText As String = My.Computer.FileSystem.ReadAllText(My.Settings.TempFile)
My.Computer.FileSystem.WriteAllText(My.Settings.DefaultOutput, fileText, True, System.Text.Encoding.ASCII)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top