Converts to pascal casing. "fooBar" becomes "FooBar" "foobar" becomes "Foobar" - CSharp System

CSharp examples for System:String Convert

Description

Converts to pascal casing. "fooBar" becomes "FooBar" "foobar" becomes "Foobar"

Demo Code


using System.Text;
using System.Security.Cryptography;
using System.Linq;
using System.IO;/*from w  ww  .ja  va  2 s .  co m*/
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        #if !PORTABLE
        /// <summary>
        /// Converts to pascal casing.
        /// "fooBar" becomes "FooBar"
        /// "foobar" becomes "Foobar"
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string ToPascalCase(this String source, CultureInfo cultureInfo)
        {
            if (String.IsNullOrEmpty(source))
            {
                return source;
            }
            else if (source.Length == 1)
            {
                return source.ToUpper(cultureInfo);
            }
            else
            {
                return source[0].ToString().ToUpper(cultureInfo) + String.Join("", source.Substring(1));
            }
        }
        #endif
        /// <summary>
        /// Converts to pascal casing.
        /// "fooBar" becomes "FooBar"
        /// "foobar" becomes "Foobar"
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string ToPascalCase(this String source)
        {
            if (String.IsNullOrEmpty(source))
            {
                return source;
            }
            else if (source.Length == 1)
            {
                return source.ToUpper();
            }
            else
            {
                return source[0].ToString().ToUpper() + String.Join("", source.Substring(1));
            }
        }
}

Related Tutorials