文本文件 ANSI 格式 转换为 Unicode 格式,该怎么解决
文本文件 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
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
但就取得某一个字符的ASC码可以考虑使用:AscW函数,它实际上返回的是UniCode编码,但由于ASCII和UniCode在0~127范围内是相同的,而超出了127,ASCII编码就没有实际意义了。所以,ASCW可以通用。
------解决方案--------------------
保存后的文本默认的是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
------解决方案--------------------
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
------解决方案--------------------
但就取得某一个字符的ASC码可以考虑使用:AscW函数,它实际上返回的是UniCode编码,但由于ASCII和UniCode在0~127范围内是相同的,而超出了127,ASCII编码就没有实际意义了。所以,ASCW可以通用。
------解决方案--------------------
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"