Skip Navigation Links  
Skip Navigation Links
Home
ADO.NET
ASP.NET
C#Expand C#
Visual Basic
 

the .NET professional resource

  Visual Basic

 
 Site information offered by Developers MVP (formers and/or actives)

'Proper case' people's names

Using the .NET way and the old VB way

Author: Joe LeVasseur
Published: Mon, 10 Apr 2006
Revised: Mon, 10 Apr 2006
   

Here is something to 'Proper case' people's names- using the .Net way and the old VB way.

 


Here is something to 'Proper case' people's names- using the .Net way and the old VB way.
Joe

'/// Simple function to 'Proper Case' names. (AKA TitleCase)
'/// I actually have one that adjusts for O'Donnell, McDonald etc that
'/// I wrote for work. 4/09/2006 Joe LeVasseur
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Debug.WriteLine(ToProperCase("guille som"))
    Debug.WriteLine(ToProperCase("GUILLE SOM"))
    Debug.WriteLine(ToProperCase("guille SOM"))
 
    Debug.WriteLine(ToProperCase("guille som", True))
    Debug.WriteLine(ToProperCase("GUILLE SOM", True))
    Debug.WriteLine(ToProperCase("guille SOM", True))
 
    Debug.WriteLine(ToProperCase("ronald mcdonald"))
    Debug.WriteLine(ToProperCase("ronald mcdonald", True))
 
    ' Output:
    'Guille Som 
    'Guille Som 
    'Guille Som 
    'Guille Som 
    'Guille Som 
    'Guille Som 
    'Ronald Mcdonald 
    'Ronald Mcdonald 
 
End Sub
 
Public Function ToProperCase(ByVal InputStr As String, Optional ByVal UseStrConv As Boolean = False) As String
    Dim Tmp As String
    Dim ci As New System.Globalization.CultureInfo("en-US", False)
    '-------------------------------
    If (UseStrConv = True) Then
        Tmp = StrConv(InputStr, VbStrConv.ProperCase)
    Else
        Tmp = InputStr.ToLower  ' ToTitleCase doesn't 'Do' all uppercase
        Tmp = ci.TextInfo.ToTitleCase(Tmp)
    End If
    Return Tmp
End Function
 
 
Link a la versión en español de este artículo en elGuille.info Spanish version of this article
15 points from 3 users (views: 102)
To rate this article, please click a rating, and then click the Rank this article button
dotNetPro.info v0.0.0.79 - ASP.NET 2.0 (v2.0.50727.832) - Last updated: jue, 19 jul 2007 07:03:55 GMT
  You can use the code for free, if you want to publish it in a Web site, please contact: info@dotNetPro.info