rust 切片

fn main() {
  // 切片
  let s = String::from("Hello world");
  let substr = &s[1..6];
  let hello = &s[..5];
  let world = &s[6..];
  let whole = &s[..];
  println!("subtr: {}", substr);
  println!("hello: {}", hello);
  println!("world: {}", world);
  println!("whole: {}", whole);
}

猜你喜欢

转载自blog.csdn.net/qq2942713658/article/details/114731449