unity 字符串转字节
时间: 2023-09-22 22:11:57 浏览: 48
在 Unity 中,可以使用 System.Text.Encoding 类将字符串转换为字节数组。以下是一个示例代码:
```csharp
string str = "Hello World!";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
```
在上面的代码中,我们将字符串 "Hello World!" 转换为 UTF-8 编码的字节数组。您可以根据需要选择不同的编码类型。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)