文本文件 ANSI 格式 转换为 Unicode 格式
保存后的文本默认的是ANSI格式,为了适应不同语言系统下,文本文件由ANSI格式转换为Unicode 格式,用代码实现。
文本中内容格式如下:
NORTH
Num Gx Gy Gz GHS Inc AZm MTF DIP MF Gtot
-------------------------------------------
1 0.37 -0.93 0.00 248.57 90.00 212.65 87.95 56.89 47.900 1.0041
2 0.37 -0.93 0.00 248.57 90.00 212.65 87.95 56.89 47.900 1.0041
3 0.37 -0.93 0.00 248.59 90.00 212.66 87.95 56.92 47.880 1.0034
[最优解释]
Private Sub Command1_Click ()
Dim sFile As String
Open "C:\filename.txt" For Input As #1
sFile = StrConv(InputB$(LOF(1), #1), vbUnicode)
Close #1
End Sub
f = "a.txt"
With CreateObject("Adodb.Stream")
.Mode = 3'adModeReadWrite
.Type = 2'adTypeText
.Charset = "GB2312"'ansi
.Open
.LoadFromFile f
s = .ReadText
.Flush
.Close
.Mode = 3
.Type = 2
.Charset = "Unicode"
.Open
.WriteText s
.SaveToFile f, 2'adSaveCreateOverWrite
.Flush
.Close
End With
MsgBox "ok"
Private Sub Command1_Click()
Dim sFile As String
Dim fso, file
Open "C:\filename.txt" For Input As #1
sFile = StrConv(InputB$(LOF(1), #1), vbUnicode)
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.CreateTextFile("c:\unicode.txt", True)
file.write sFile
file.Close
Close #1
End Sub