Answer the question
In order to leave comments, you need to log in
How to find the number of occurrences of characters in a string using extension methods?
We need to find the number of occurrences of characters from the char[] Splitters array in the input string using extension methods. Those. if:
input = "1010" then input.Count(...) = 0;
input = "10*10", then input.Count(...) = 1;
input = "10*10/", then input.Count(...) = 2;
and so on ...
Specifically, it is of interest that the number of occurrences be no more than one.
I thought to do it this way, but I haven’t worked with expanders yet and somehow it doesn’t work:
char[] Splitters = { ' ', '*', 'x', '/', ',', '&', '^' };
//...
bool ok = false;
for (int i = 0; i < Splitters.Length; i++){
if (input.Count(x => x == input.Contains(Splitters[i])) < 2)
{
ok = true;
}
else
ok = false;
}
Answer the question
In order to leave comments, you need to log in
The task is almost solved. It remains to turn on the head.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question