【Rust】字符串切片(一)
作者:互联网
环境
- Time 2022-03-24
- Rust 1.59.0
示例
len
fn main() {
let name = "JiangBo";
println!("{:?}", name.len());
}
is_empty
fn main() {
let name = "JiangBo";
println!("{:?}", name.is_empty());
}
is_char_boundary
fn main() {
let name = "JiangBo";
println!("{:?}", name.is_char_boundary(5));
}
as_bytes
fn main() {
let name = "JiangBo";
let name = name.as_bytes();
println!("{:?}", name);
}
as_bytes_mut
fn main() {
let mut name = String::from("JiangBo");
let name = unsafe { name.as_bytes_mut() };
println!("{:?}", name);
}
as_ptr
fn main() {
let name = "JiangBo";
println!("{:p}", name.as_ptr());
}
as_mut_ptr
fn main() {
let mut name = String::from("JiangBo");
println!("{:p}", name.as_mut_ptr());
}
get
fn main() {
let name = "JiangBo";
println!("{:?}", name.get(5..));
}
get_mut
fn main() {
let mut name = String::from("JiangBo");
println!("{:?}", name.get_mut(5..));
}
总结
了解了字符串切片中相关的一些方法。
附录
标签:mut,name,JiangBo,切片,let,fn,字符串,main,Rust 来源: https://www.cnblogs.com/jiangbo4444/p/16322798.html