let s= Sring::from(❤)
s.trim_matches!(char::is_alphabetic & char::is_numeric);//.trim_matches(❤);
//(!char::is_alphabetic & !char::is_numeric)
I want delete all such symbols or only , example above give error:
1)error: no implementation for fn(char) -> bool {char::methods::<impl char>::is_alphabetic} & fn(char) -> bool {char::methods::<impl char>::is_numeric}
2)possible error: expected bool found fn(char) -> bool
The code example you give contains a few syntactic errors, and you could also do a better job providing the full error message. It’d be easiest to help you if you provided the full error message together with a complete code example so that we can reproduce that error message ourselves. I’m also not quite sure if what you want to achieve is entirely in line with the kind of code you’ve written here—not that trim_matches only removes parts of the string that are in the beginning or the end of the string, not in the middle.
Anyways, the argument to trim_matchescan be a function from char to bool, you’re trying to combine two such functions here char::is_alphabetic and char::is_numeric and you can’t do that with & the way you’re trying to do. You’d need to create a new function, or a closure here, also you probably want a disjunction (logical OR-operation) instead of a conjunction (logical AND-operation), because AFAIK no character would be both alphabetic and numeric. Try something like
The expression |c| c.is_alphabetic() || c.is_numeric() is a closure that takes an argument c (which is inferret to be of type char) and returns a boolean. The inner expression c.is_alphabetic() || c.is_numeric() is of type bool and uses the argument c. It’s using method-call syntax and is equivalent to something like char::is_alphabetic(c) || char::is_numeric(c). The || operator is a logical “OR” operation.