Answers for "how to count each character number of occurrences of a character in a string in c#"

C#
7

c# count number of occurrences in string

char myChar = 'x';
string myString = "xyz";

int count = myString.Count(s => s == myChar);
Posted by: Guest on February-24-2020
0

count number of specific characters in string c#

# cCopyusing System;
using System.Linq;

namespace get_first_char_of_string
{
    class Program
    {
        static void Main(string[] args)
        {
            string source = "/once/upon/a/time/";
            int count = source.Split('o').Length - 1; 
            Console.WriteLine(count);
        }
    }
}
Posted by: Guest on November-15-2021

Code answers related to "how to count each character number of occurrences of a character in a string in c#"

C# Answers by Framework

Browse Popular Code Answers by Language