gpt4 book ai didi

c# - 需要帮助转换

转载 作者:行者123 更新时间:2023-11-28 03:49:59 25 4
gpt4 key购买 nike

您好,需要帮助将此 C++ 代码转换为 C#

sprintf((char *)(dataBuffer), "Failed statistics read, device %s", device); 

dataBuffer是byte[]

我写了这个,但是在将字符串转换为 byte[] 时出错

  dataBuffer = string.Format("Failed statistics read, device {0}", device);

最佳答案

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);

关于c# - 需要帮助转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5853378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com