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

  • 關於本站
  • 免責聲明