Blog of a Filipino Developer about C#, VB.NET, ASP.NET, Java, PHP, SQL Server, MySql and Oracle RSS 2.0
 Tuesday, August 19, 2008

Ever thought of how to capitalize the first letter of every word in a string? Here's how:

[C#]

using System;
using System.Globalization;

namespace KeithRull.CapitalizingLetters
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string textToTransform = "keith, you need to post more blogs!";

            Console.WriteLine("Original text: " + textToTransform);

            //capitalizing the first letter of our text using the current culture
            Console.WriteLine("Capitalize using the current culture: "
                + CultureInfo.CurrentCulture.TextInfo.ToTitleCase(textToTransform));

            //capitalizing the first letter of our text using a defined culture
            CultureInfo newCultureInfo = new CultureInfo("zh-Hans", false);
            TextInfo textInfo = newCultureInfo.TextInfo;
            Console.WriteLine("Capitalize using a specified culture: " + textInfo.ToTitleCase(textToTransform));

            Console.Read();
        }
    }
}

[VB.NET]

Imports System
Imports System.Globalization
 
Namespace KeithRull.CapitalizingLetters
    Friend Class Program
        Shared  Sub Main(ByVal args() As String)
            Dim textToTransform As String =  "keith, you need to post more blogs!" 
 
            Console.WriteLine("Original text: " + textToTransform)
 
            'capitalizing the first letter of our text using the current culture
            Console.WriteLine("Capitalize using the current culture: "
                Dim CultureInfo.CurrentCulture.TextInfo.ToTitleCase(textToTransform)) As +
 
            'capitalizing the first letter of our text using a defined culture
            Dim NewCultureInfo As CultureInfo =  New CultureInfo("zh-Hans",False) 
            Dim textInfo As TextInfo =  NewCultureInfo.TextInfo 
            Console.WriteLine("Capitalize using a specified culture: " + textInfo.ToTitleCase(textToTransform))
 
            Console.Read()
        End Sub
    End Class
End Namespace

HTH

Tuesday, August 19, 2008 5:54:48 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET | Tutorial
Archive
<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Keith Rull
Sign In
Statistics
Total Posts: 260
This Year: 57
This Month: 0
This Week: 0
Comments: 116
Themes
Pick a theme:
Ads
All Content © 2008, Keith Rull
DasBlog theme 'Business' created by Christoph De Baene (delarou)