1

how can i capitalize every 1st letter in every word anyone? i'm a newbie so this would be a great help.

like this david paul to David Paul

davz_11
  • 127
  • 2
  • 5
  • 14

3 Answers3

5
var titleCaseStr = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input);
EZI
  • 14,888
  • 2
  • 26
  • 32
1
    string s = "Capitalize first letter in every word";

    System.Globalization.CultureInfo cultureInfo =  System.Threading.Thread.CurrentThread.CurrentCulture;
    System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;

    s = textInfo.ToTitleCase(s.ToLower());
TaW
  • 50,936
  • 8
  • 63
  • 99
1

This can be achieved simply by following method

        string s = "my test string";
        char[] c = s.ToArray();
        bool CapitalNext = true;
        string o = null;

        foreach (char ch in c)
        {

            if (CapitalNext)
                o += ch.ToString().ToUpper();
            else
                o += ch.ToString();

            CapitalNext = false;

            if (char.IsWhiteSpace(ch))
            {
                CapitalNext = true;
            }
        }
        return o;
Madhawas
  • 361
  • 2
  • 15