h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Count of repeated characters in String in C#.net

Function/ Method:
public static int countofrepeatedchar(string inputstring, char ch)
        {
            char[] Inputstring = inputstring.ToCharArray();
            char Ch = ch;
            int cntofchar = Inputstring.Length;
                foreach (char chr in Inputstring)
                {
                    if (chr == Ch)
                    {
                        result++;
                    }
       
            }


            return result;
        }

int res = countofrepeatedchar("123456123",'4');
            MessageBox.Show(res.ToString());

No comments:

Post a Comment