Reputation: 1526
I got as code in VB6, which need to be converted in C#. I have googled it but didn't get any concrete answer.
VB code:
Dim strTemp = StrConv(strTemp , vbFromUnicode)
I tried to do like this in c#:
var strTemp = System.Runtime.InteropServices.Marshal.StringToBSTR(strTemp);
I think this is not correct.
Any suggestions? what would be the correct interpetation of above vb6 code in c#.
Upvotes: 2
Views: 2464
Reputation: 5733
This is a conversion of a Unicode string to an Ansi string, by system default code page.
StrConv(strTemp , vbFromUnicode)
In C#, you need to found out the default code page by ANSICodePage from current culture
int codepage = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage;
byte[] convertedBytes = Encoding.GetEncoding(codepage).GetBytes(unicodeString);
string convertedAsciiString = System.Text.Encoding.ASCII.GetString(convertedBytes);
Upvotes: 3