|
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
|