Convert string from pascal case to human readable string pascalCaseExample => Pascal Case Example - CSharp System

CSharp examples for System:String Convert

Description

Convert string from pascal case to human readable string pascalCaseExample => Pascal Case Example

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Reflection;
using System.IO;/*from  w w w  . j a  va2s  . c  o m*/
using System;
using Microsoft.VisualBasic;
using System.Threading;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{
        /// <summary>
                /// Convert string from pascal case to human readable string
                /// <example>pascalCaseExample => Pascal Case Example</example>
                /// </summary>
                /// <param name="s">The string</param>
                /// <returns>human readable string</returns>
                public static string ToHumanFromPascal(string s)
                {
                        StringBuilder sb = new StringBuilder();
                        char[] ca = s.ToCharArray();
                        sb.Append(ca[0]);
                        for (int i = 1; i < ca.Length - 1; i++)
                        {
                                char c = ca[i];
                                if (Char.IsUpper(c) && (Char.IsLower(ca[i + 1]) || Char.IsLower(ca[i - 1])))
                                {
                                        sb.Append(" ");
                                }
                                sb.Append(c);
                        }
                        sb.Append(ca[ca.Length - 1]);
 
                        return sb.ToString();
                }
}

Related Tutorials