保存文件的编码问题
怎样用unicode保存字符串成文件?我的这段代码是:
Sub saverecord(ByVal content As String)
With SaveFileDialog1
.Title = "保存记录"
.CheckFileExists = False
.CheckPathExists = False
.CreatePrompt = True
.Filter = "Excel逗号分隔文件(*.csv)|*.csv"
.ShowDialog()
savefile = .FileName(savefile已在以前声明)
End With
If savefile = "" Then
MessageBox.Show("请输入您要保存的文件名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
Else
Dim recordwriter As StreamWriter
recordwriter = File.CreateText(savefile)
recordwriter.Write(content)
recordwriter.Close()
End If
End Sub
然后,在menuitem的事件中使用,保存的文件是UTF-8编码的,在记事本里能正常显示,在excel里就不行了。
怎样才能以unicode保存文件呢?