System.Console.WriteLine(char.ToUpper(str[0]) + str.Substring(1));
using static System.Globalization.CultureInfo;
var str = CurrentCulture.TextInfo.ToTitleCase(sortColumn.ToLower().Trim());
// first letter of string
private string CapitalizeFirst (string input) {
char.ToUpper(myString[0]) + myString[1..]; // captalizes first letter
}
// first letter of each word
private string CapitalizeAll (string input) {
var words = input.Split(' '); // create array of words
// loop through all words and capitalize them
for (int i = 0; i < words.length; i++) {
words[i] = CapitalizeFirst (words[i]);
}
return string.Join(' ', words);
}
string myString = "hello world";
// results
CapitalizeFirst(myString); // "Hello world"
CapitalizeAll(myString); // "Hello World"
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();
}
}
public static class Capitalize
{
public static string Word(string input)
{
if (string.IsNullOrEmpty(input))
{
return string.Empty;
}
var a = input.ToCharArray();
a[0] = char.ToUpper(a[0]);
for (var i = 1; i < a.Length; i++)
{
a[i] = char.ToLower(a[i]);
}
return new string(a);
}
public static string Sentence(string input)
{
return string.Join(" ", input.Split(' ').Select(Word));
}
}