知识卡片
片段拼接可指定分隔符
一组文本片段可用切片方法 concat() 直接相连,或用 join(sep) 在相邻片段之间插入同一个分隔符。["veni", "vidi", "vici"].join(", ") 会得到 "veni, vidi, vici"。这两个方法同时支持 [&str] 和 [String],数组与向量皆可调用。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Fundamental Types 构造、格式化和拼接字符串 · 查看原书依据
These methods are defined for slices of type [&str] and [String], and are therefore available on arrays and vectors as well.
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|构造、格式化和拼接字符串,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#string`
- 结论依据:原文给出同一组片段的 concat 和 join 结果,随后指出方法适用的两种切片元素类型。
- 原始内容:These methods are defined for slices of type [&str] and [String], and are therefore available on arrays and vectors as well.