Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i have a textbox and ill write one name in that and i want to know for example how many word like "a" in that name i want to count it
With Respect
Posted
Comments
StM0n 9-Oct-14 2:30am    
Do you want to count the number of certain words or letters? Have you tried regular expressions?
Avenger1 9-Oct-14 2:35am    
i want to find a word in sentence like "a,i,o,u" and count how many these words in the sentence
Sinisa Hajnal 9-Oct-14 2:40am    
And you cannot google this because...? What have you tried until now?

1 solution

Do like this

C#
textBox1.Text = "abc";
int count = textBox1.Text.Count(f => f == 'a');

or
int count1 = Regex.Matches(textBox1.Text, "a").Count;
 
Share this answer
 
v2
Comments
Maciej Los 9-Oct-14 2:44am    
Nice!
+5!
Avenger1 9-Oct-14 2:49am    
thanks and now i want to do it richtextbox and how can i do it in just one line, if you right in the next line it do it of zero for example
in line one we have 5 "a" and how can i find how many in line 2 not count all lines
Animesh Datta 9-Oct-14 2:58am    
My 5!
Avenger1 9-Oct-14 3:00am    
i want each line has count not all RichTextBox in one count

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900