TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ever Green
NA
6
0
How to count specific letterr in a string?
Nov 11 2009 4:20 PM
I Created a windows application in c#.net and I wanna count specific character in a string for example i wanna count how many "g" in "Debugging" string:
Someting is wrong with the Substring().I debugged it and i saw it is only check the first character of the string. Any help??
Code:
private void btnclick_Click(object sender, EventArgs e)
{
int lettercount = 0;
const string strtext = "Debugging";
string letter;
for (int i = 0; i < strtext.Length; i++)
{
letter = strtext.Substring(0,1);
if (letter == "g")
{
lettercount++;
}
}
textBox1.Text = "g appears" + lettercount + " " + "times";
}
Output:
"g appears 0 times"
Reply
Answers (
4
)
Prolem in DataGridView using c#
MonthCalendar control