Uppercasing the first char in a string without StringBuilder - CSharp Language Basics

CSharp examples for Language Basics:StringBuilder

Description

Uppercasing the first char in a string without StringBuilder

Demo Code

using System;/*from  w ww . jav a 2  s .  c  om*/
using System.Text;                // Need for type UTF8Encoding.
using System.Globalization;       // Need for cultures.
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("\nUppercase the first char of a string in various ways:");
        string name = "chuck";
        string properName = char.ToUpper(name[0]).ToString() + name.Substring(1, name.Length - 1);
        Console.WriteLine("{0} becomes {1}", name, properName);
    }
}

Result


Related Tutorials