Converts a string to a Pascal case representation, e.g. ThisIsPascalCasing with an initial upper case character. - CSharp System

CSharp examples for System:String Convert

Description

Converts a string to a Pascal case representation, e.g. ThisIsPascalCasing with an initial upper case character.

Demo Code

// Copyright (c) Microsoft Corporation. All rights reserved.
using System.Text;
using System.Globalization;
using System;/*from w ww.  j a  v a  2 s.  com*/

public class Main{
        /// <summary>
        /// Converts a string to a Pascal case representation, e.g. <c>ThisIsPascalCasing</c> with 
        /// an initial upper case character.
        /// </summary>
        /// <param name="value">The string to convert.</param>
        /// <returns>The Pascal cased string; or the original string if no modifications were necessary.</returns>
        public static string ToPascalCase(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return value;
            }

            if (char.IsUpper(value[0]))
            {
                return value;
            }

            StringBuilder pascal = new StringBuilder(value);
            pascal[0] = Char.ToUpperInvariant(value[0]);
            return pascal.ToString();
        }
}

Related Tutorials