VeecoTech
VeecoTech

Reputation: 2143

need to help to convert

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

Answers (1)

tidwall
tidwall

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

Related Questions