作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我收到此错误
expected
&str
, foundchar
// Expected output
// -------
// h exists
// c exists
fn main() {
let list = ["c","h","p","u"];
let s = "Hot and Cold".to_string();
let mut v: Vec<String> = Vec::new();
for i in s.split(" ") {
let c = i.chars().nth(0).unwrap().to_lowercase().nth(0).unwrap();
println!("{}", c);
if list.contains(&c) {
println!("{} exists", c);
}
}
}
我该如何解决?
最佳答案
将list
从&str
数组更改为char
数组:
let list = ['c', 'h', 'p', 'u'];
双引号
""
创建字符串文字,而单引号
''
创建字 rune 字。请参阅Rust引用中的
Literal Expressions。
关于string - 预期&str发现有 rust 的炭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66255166/
我正在复习第一学期的 C++ 类(class),我想我漏掉了什么。一个字符串占多少字节?炭? 我们得到的示例是,一些是字 rune 字,一些是字符串: 'n', "n", '\n', "\n", "\
我是一名优秀的程序员,十分优秀!