• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

Propercase in vb.net

I understand this sample help to take care of string to proper case.

johne doe to John Doe

http://www.a1vbcode.com/vbtip-159.asp

Is there a proper way of handling lastname such as mcdonalds to McDonalds? john doe II to John Doe II
Should I check the first two char if mc then change to Mc and if ii change to II ?


            Dim mystring = "john mcdonalds v "
        Dim FL As String = mystring.Trim
        If FL.Contains(" ") Then
            FL = StrConv(FL, VbStrConv.ProperCase)
            Dim ar_II As String() = FL.Split(" ")
            Dim mystr As String
            Dim nustr As String = ""
            For Each mystr In ar_II    
                If mystr.StartsWith("Mc") Then
                    Dim I As Integer = mystr.Length
                    If I > 2 Then
                        mystr = mystr.Substring(0, 2) & StrConv(mystr.Substring(2), VbStrConv.ProperCase)
                    End If
                End If
                Select Case mystr.ToLower
                    Case "i"
                        mystr = mystr.ToUpper
                    Case "ii"
                        mystr = mystr.ToUpper
                    Case "iii"
                        mystr = mystr.ToUpper
                    Case "v"
                        mystr = mystr.ToUpper
                    Case "vi"
                        mystr = mystr.ToUpper
                End Select
                nustr &= mystr & " "
            Next
            MessageBox.Show(nustr)
        Else
            FL = StrConv(FL, VbStrConv.ProperCase)
            MessageBox.Show(FL)
        End If
0
VBdotnet2005
Asked:
VBdotnet2005
1 Solution
 
CodeCruiserCommented:
I dont think there is a built in way of dealing with names like mcdonalds. So this would require some if else conditions.
0
 
Saqib Husain, SyedEngineerCommented:
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now