Reputation: 2143
Hi need help to convert this C++ code to C#
sprintf((char *)(dataBuffer), "Failed statistics read, device %s", device);
The dataBuffer is byte[]
I wrote this, but with error converting string to byte[]
dataBuffer = string.Format("Failed statistics read, device {0}", device);
Upvotes: 0
Views: 76
Reputation: 6949
String str = string.Format("Failed statistics read, device {0}", device);
byte[] dataBuffer = System.Text.Encoding.ASCII.GetBytes(str);
// for 2-byte unicode
byte[] dataBuffer = System.Text.Encoding.Unicode.GetBytes(str);
// for UTF8 unicode
byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(str);
Upvotes: 2