- Local time
- 8:53 AM
- Posts
- 1,128
- OS
- windows 11
What I did so far is this then
had to use as object because sr.currentencoding, to capture the value is not a stringDim Fileunicode type as object
tester("C:\Temp\MyTest.txt", Fileunicodetype)
Dim content As String
If Fileunicodetype = "System.Text.UTF8Encoding" Then content = IO.File.ReadAllText(FilenameToBreak, System.Text.Encoding.UTF8)
If Fileunicodetype = "System.Text.UnicodeEncoding" Then content = IO.File.ReadAllText(FilenameToBreak, System.Text.Encoding.BigEndianUnicode)
If Fileunicodetype = "System.Text.UTF32Encoding" Then content = IO.File.ReadAllText(FilenameToBreak, System.Text.Encoding.UTF32)
Public Sub tester(ByRef FileName As String, ByRef FileUnicodetype As Object)
'Dim path As String = "c:\temp\MyTestunicodeencoding.txt"
Try
' If File.Exists(path) Then
' File.Delete(path)
' End If
'Use an encoding other than the default (UTF8).
' Dim sw As StreamWriter = New StreamWriter(path, False, New UTF32Encoding())
' Dim sw As New StreamWriter(path, False, New UTF8Encoding())
'Dim sw As New StreamWriter(path, False, New UTF32Encoding())
'Dim sw As New StreamWriter(path, False, New UTF7Encoding())
'Dim sw As New StreamWriter(path, False, New UnicodeEncoding())
' sw.WriteLine("This")
' sw.WriteLine("is some text")
' sw.WriteLine("to test")
' sw.WriteLine("Reading")
' sw.Close()
'********************************************************************
Dim sr As New StreamReader(FileName, True)
Dim Countchars As Integer
Do While sr.Peek() >= 0
'Debug.Write(Convert.ToChar(sr.Read()))
Countchars += 1
If Countchars > 10 Then Exit Do
Loop
Debug.WriteLine(" ")
'Test for the encoding after reading, or at least
'after the first read.
Debug.Print("The encoding used was {0}.", sr.CurrentEncoding)
Debug.WriteLine(" ")
FileUnicodetype = sr.CurrentEncoding
sr.Close()
Catch e As Exception
Debug.Print("The process failed: {0}", e.ToString())
Debug.WriteLine(" ")
FileUnicodetype = "EncodingUnknown"
End Try
UnicodeEncoding Class (System.Text)
Represents a UTF-16 encoding of Unicode characters.learn.microsoft.com
My Computer
System One
-
- OS
- windows 11
- Computer type
- PC/Desktop
- Manufacturer/Model
- some kind of old ASUS MB
- CPU
- old AMD B95
- Motherboard
- ASUS
- Memory
- 8gb
- Hard Drives
- ssd WD 500 gb