logo
  • 教程列表
  • SO官方文档
  • 字符串
    • 基本字符串操作
    • 拆分一个字符串
    • 打破长字符串文字
    • 字符串切片
    • 从借来到拥有
  1. StackOverflow 文档
  2. Rust 教程
  3. 字符串
  4. 拆分一个字符串

拆分一个字符串

Created: November-22, 2018

let strings = "bananas,apples,pear".split(",");

split 返回一个迭代器。

for s in strings {
  println!("{}", s)
}

并且可以使用 Iterator::collect 方法在 Vec 中收集。

let strings: Vec<&str> = "bananas,apples,pear".split(",").collect(); // ["bananas", "apples", "pear"]
  • 打破长字符串文字
  • 基本字符串操作

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明