从文档来看,目前尚不清楚.在Java中,您可以使用如下split方法:
"some string 123 ffd".split("123");
Run Code Online (Sandbox Code Playgroud) use std::collections::HashSet;
fn character_count(needles: &HashSet<char>, needle_type: &str, input: &str) -> i32 {
for needle in needles {
let mut needle_custom;
if needle_type == "double" {
needle_custom = needle.to_string() + &needle.to_string();
} else {
needle_custom = needle.to_string() + &needle.to_string() + &needle.to_string();
}
if input.contains(needle_custom) {
println!("found needle {:?}", needle_custom);
}
}
return 1;
}
Run Code Online (Sandbox Code Playgroud)
use std::collections::HashSet;
fn character_count(needles: &HashSet<char>, needle_type: &str, input: &str) -> i32 {
for needle in needles {
let mut needle_custom;
if needle_type == "double" {
needle_custom = …Run Code Online (Sandbox Code Playgroud) let mystring = format!("the quick brown {}", "fox...");
assert!(mystring.ends_with(mystring));
Run Code Online (Sandbox Code Playgroud)
错误:
the trait `std::ops::FnMut<(char,)>` is not implemented for `std::string::String`
Run Code Online (Sandbox Code Playgroud)
改变mystring.ends_with(mystring)以mystring.ends_with(mystring.as_str())修复它.
为什么这个错误如此神秘?
如果我在不使用格式的情况下创建字符串,请说:
let mystring = String::from_str("The quick brown fox...");
assert!(mystring.ends_with(mystring));
Run Code Online (Sandbox Code Playgroud)
错误更容易理解:
error[E0599]: no method named `ends_with` found for type
`std::result::Result<std::string::String, std::string::ParseError>`
in the current scope
Run Code Online (Sandbox Code Playgroud)