I'm new to C#, and I'm trying to figure something out.
I'm trying to count the occurrence of a single digit to that in a string.
What I mean by this is The user types in a sentence in a multiline textbox and below in a separate text field a single letter. I need to check how many times that single letter occurs in the sentence.
Currently, I have the input of the two text fields by using this
string InputSingleline = SingleLineTxtBox.Text;
string InputMultiline = MultiLineTxtBox.Text;
int Count = InputMultiline.Count(f => f == SingleLineTxtBox);
Firstly you should count the occurrences of InputSingleline
instead of SingleLineTxtBox
since you have already set the InputSingleline
to SingleLineTxtBox.Text
. And secondly the InputSingleline
is a string with one character, so you need to use something like FirstOrDefault
to return that character from this string:
int Count = InputMultiline.Count(f => f == InputSingleline.FirstOrDefault());