Rust String 用法总结
KuangjuX
·
2021-10-19
·
via KuangjuX(狂且)
- String + String -> String:
1 2 3
| let s1 = "0"; let s2 = "1"; let s = format!("{}{}", s1, s2);
|
1 2 3
| let s1: &str; let s: String; s.push_str(s1);
|
1 2 3 4
| let s1: &str; let s2: &str; let s = String::from_str(s1); s.push_str(s2);
|
1 2 3
| let s: String; let s1: &str = s.as_str(); let s2: &mut str = s.as_mut_str();
|
1 2
| let s: String; let s1: &[u8] = s.as_bytes();
|
1 2
| let s: String let s1: &mut Vec<u8> = s.as_mut_vec();
|
1 2
| let s: &str; let s1 = String::from_str(s);
|
1 2 3
| let s: &[u8]; let s1 = String::from_utf8_lossy(s); let s2 = String::from_utf8(s.to_vec()).unwrap();
|
1 2
| let s: Vec<u8>; let s1 = String::from_utf8(s).unwrap();
|
1 2
| let s: String; let c = s.chars().nth(index).unwrap();
|
1 2 3 4
| let s: String; for c in s.chars() { }
|
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。