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
  • 135
  • 2
  • 6
  • 14

3 Answers3

5
var titleCaseStr = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input);
EZI
  • 15,209
  • 2
  • 27
  • 33
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
  • 53,122
  • 8
  • 69
  • 111
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
  • 371
  • 1
  • 2
  • 15