惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
博客园 - Franky
F
Fortinet All Blogs
D
Docker
博客园 - 司徒正美
腾讯CDC
Recent Announcements
Recent Announcements
The Cloudflare Blog
B
Blog RSS Feed
GbyAI
GbyAI
T
Tailwind CSS Blog
雷峰网
雷峰网
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志

KuangjuX(狂且)

提高 Directory Cache 性能 高速缓存技术(Cache) Chisel 学习笔记 随笔(一) 指令级并行技术 TLB MMU 笔记(基于 MIPS) Verilator 学习笔记 MIT-6.S081-mmap MIT-6.S081 Networking MIT-6.S081 Lazy Page Allocation MIT-6.S081 Copy on Write Fork MIT-6.S081 User Level Threads 2021年终总结 xv6-riscv中的KPTI机制 RISC -V N扩展 io_uring 阅读笔记 在Ubuntu中升级Linux内核 飞书Rust实习面试 Rust并发安全总结
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);
  • String + &str -> String:
1
2
3
let s1: &str;
let s: String;
s.push_str(s1);
  • &str + &str -> String:
1
2
3
4
let s1: &str;
let s2: &str;
let s = String::from_str(s1);
s.push_str(s2);
  • String -> &str:
1
2
3
let s: String;
let s1: &str = s.as_str();
let s2: &mut str = s.as_mut_str();
  • String -> &[u8]:
1
2
let s: String;
let s1: &[u8] = s.as_bytes();
  • String -> &mut Vec< u8 >
1
2
let s: String
let s1: &mut Vec<u8> = s.as_mut_vec();
  • &str -> String:
1
2
let s: &str;
let s1 = String::from_str(s);
  • &[u8] -> String:
1
2
3
let s: &[u8];
let s1 = String::from_utf8_lossy(s);
let s2 = String::from_utf8(s.to_vec()).unwrap();
  • Vec< u8 > -> String:
1
2
let s: Vec<u8>;
let s1 = String::from_utf8(s).unwrap();
  • 通过索引获取 String 中的 字符
1
2
let s: String;
let c = s.chars().nth(index).unwrap();
  • 遍历 String
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.