capitalize csharp

Code Example - capitalize csharp

                
                        string input = "hello!";
Console.Write(char.ToUpper(input[0]) + input.Substring(1))

//prints "Hello!"
                    
                
 

csharp capitalize first letter

                        
                                string text = "john smith";

// "John smith"
string firstLetterOfString = text.Substring(0, 1).ToUpper() + text.Substring(1);

// "John Smith"
// Requires Linq! using System.Linq;
string firstLetterOfEachWord =
		string.Join(" ", text.Split(' ').ToList()
				.ConvertAll(word =>
						word.Substring(0, 1).ToUpper() + word.Substring(1)
				)
		);
                            
                        
 

first sentence letter capital in csharp

                        
                                public static class StringExtension
{
    public static string CapitalizeFirst(this string s)
    {
        bool IsNewSentense = true;
        var result = new StringBuilder(s.Length);
        for (int i = 0; i < s.Length; i++)
        {
            if (IsNewSentense && char.IsLetter(s[i]))
            {
                result.Append (char.ToUpper (s[i]));
                IsNewSentense = false;
            }
            else
                result.Append (s[i]);

            if (s[i] == '!' || s[i] == '?' || s[i] == '.')
            {
                IsNewSentense = true;
            }
        }

        return result.ToString();
    }
}