Proper Case Function in C#

Status
Not open for further replies.

ohsuria

Yellow Belt
C# only have ToLower() and ToUpper() function, there's no ToProper() :)
Instead of using loop to proper your strings, you can try below function.

Code:
public static string ToProper(String strText)  
        {  
            string rText = "";  
            try  
            {  
                System.Globalization.CultureInfo cultureInfo =   
                    System.Threading.Thread.CurrentThread.CurrentCulture;  
                System.Globalization.TextInfo TextInfo = cultureInfo.TextInfo;
                rText = TextInfo.ToTitleCase(strText);  
            }  
            catch  
            {
                rText = strText;  
            }  
            return rText;  
        }
 
Status
Not open for further replies.
Top