如何在 C# 中将 vb6 'vbFromUnicode' 转换为字符串
How to convert vb6 'vbFromUnicode' to string in C#
我得到的是VB6中的代码,需要用C#进行转换。我用谷歌搜索了它,但没有得到任何具体答案。
VB代码:
Dim strTemp = StrConv(strTemp , vbFromUnicode)
我尝试在 c# 中这样做:
var strTemp = System.Runtime.InteropServices.Marshal.StringToBSTR(strTemp);
我认为这是不正确的。
有什么建议吗? c# 中上述 vb6 代码的正确解释是什么。
根据系统默认代码页,这是 Unicode 字符串到 Ansi 字符串的转换。
StrConv(strTemp , vbFromUnicode)
在 C# 中,您需要通过 ANSICodePage 从当前区域性
中找出默认代码页
int codepage = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage;
byte[] convertedBytes = Encoding.GetEncoding(codepage).GetBytes(unicodeString);
string convertedAsciiString = System.Text.Encoding.ASCII.GetString(convertedBytes);
我得到的是VB6中的代码,需要用C#进行转换。我用谷歌搜索了它,但没有得到任何具体答案。
VB代码:
Dim strTemp = StrConv(strTemp , vbFromUnicode)
我尝试在 c# 中这样做:
var strTemp = System.Runtime.InteropServices.Marshal.StringToBSTR(strTemp);
我认为这是不正确的。
有什么建议吗? c# 中上述 vb6 代码的正确解释是什么。
根据系统默认代码页,这是 Unicode 字符串到 Ansi 字符串的转换。
StrConv(strTemp , vbFromUnicode)
在 C# 中,您需要通过 ANSICodePage 从当前区域性
中找出默认代码页int codepage = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage;
byte[] convertedBytes = Encoding.GetEncoding(codepage).GetBytes(unicodeString);
string convertedAsciiString = System.Text.Encoding.ASCII.GetString(convertedBytes);