Strings
-
I am using text boxes to enter names. If the text is entered in lower case letters i have put a line of code to change the first letter to upper case txtName1.Text = Char.ToUpper(txtName1.Text.Chars(0)).ToString() + txtName1.Text.Substring(1) like so. My problem is, suppose the name is double barreled like carly-anne i can change the C to a capital but how do i change the second name "anne" to "Anne" :confused: Thanks from Zeldacat
-
I am using text boxes to enter names. If the text is entered in lower case letters i have put a line of code to change the first letter to upper case txtName1.Text = Char.ToUpper(txtName1.Text.Chars(0)).ToString() + txtName1.Text.Substring(1) like so. My problem is, suppose the name is double barreled like carly-anne i can change the C to a capital but how do i change the second name "anne" to "Anne" :confused: Thanks from Zeldacat
My guess would be to look at the previous letter and convert the current letter to Upper Case if it is a ' ' or a '-'.
Mike Lasseter
-
I am using text boxes to enter names. If the text is entered in lower case letters i have put a line of code to change the first letter to upper case txtName1.Text = Char.ToUpper(txtName1.Text.Chars(0)).ToString() + txtName1.Text.Substring(1) like so. My problem is, suppose the name is double barreled like carly-anne i can change the C to a capital but how do i change the second name "anne" to "Anne" :confused: Thanks from Zeldacat
-
:)'Or you can try this. --------------with comments----------------- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Me.TextBox1.Text <> Nothing Then 'make sure the textbox value is exist. Dim NameParts As String() = Split(Me.TextBox1.Text) 'split the name parts into an array. Dim FullName As String = "" 'make a buffer to save the processed name parts. Dim nMax As Integer = NameParts.GetUpperBound(0) 'number of name parts. For i As Integer = 0 To nMax 'iterate through the element of name part array. 'Replace first character with upper case character on each elements. NameParts(i) = Mid(NameParts(i), 1, 1).ToUpper & Mid(NameParts(i), 2).ToLower FullName &= NameParts(i) & " " 'save into buffer. Next Dim xTrim As Integer = FullName.Length - 1 'count characther length in fullname FullName = Mid(FullName, 1, xTrim) 'remove space character at the end of fullname. Me.TextBox1.Text = FullName 'put the processed value back into textbox End If End Sub --------------without comments----------------- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Me.TextBox1.Text <> Nothing Then Dim NameParts As String() = Split(Me.TextBox1.Text) Dim FullName As String = "" Dim nMax As Integer = NameParts.GetUpperBound(0) For i As Integer = 0 To nMax NameParts(i) = Mid(NameParts(i), 1, 1).ToUpper & Mid(NameParts(i), 2).ToLower FullName &= NameParts(i) & " " Next Dim xTrim As Integer = FullName.Length - 1 FullName = Mid(FullName, 1, xTrim) Me.TextBox1.Text = FullName End If End Sub