Skip to content

字符串之间的相互转换

fromtofunction
&strStringString::from(s) / s.to_string() / s.to_owned()
&str&[u8]s.as_bytes()
&strVecs.as_bytes().to_vec()
String&[u8]s.as_bytes()
String&strs.as_str() / &s
StringVecs.into_bytes()
&[u8]&strstd::str::from_utf8(s).unwrap()
&[u8]Vecs.to_vec()
Vec&strstd::str::from_utf8(&s).unwrap()
VecStringString::from_utf8(s).unwrap()
Vec&[u8]&s / s.as_slice()