【问题标题】:Convert &[u8] to String [duplicate]将 &[u8] 转换为字符串 [重复]
【发布时间】:2018-05-20 13:54:46
【问题描述】:

我有一个字节数组,我想返回为std::string::String。我发现的其他答案和文档是将向量转换为字符串。

如何将字节数组&[u8] 转换为String

【问题讨论】:

标签: types rust


【解决方案1】:

它正在使用std::str::from_utf8

std::str::from_utf8(byte_array).unwrap().to_string();

Playground

【讨论】:

  • 如果你想要String,你也可以使用:String::from_utf8(byte_array.to_vec()).unwrap()
猜你喜欢
  • 2013-10-05
  • 1970-01-01
  • 2020-01-22
  • 1970-01-01
  • 1970-01-01
  • 2019-10-27
  • 2016-09-06
相关资源
最近更新 更多