[RESOLVED] [02/03] String.Split
Hello again everyone! :wave:
In my program, the user will enter Full Names of a customer. Now, what I want to achieve is to Capitalise the customer's name (Uppercase), he / she is known by.
So for example: My full names are Ron Peter, but people call me Ron. In this case, I want to convert only Ron to uppercase, and leave Peter in title case. This will produce the end result of:
RON Peter
But, if I was known as Peter, it should have looked like this:
Ron PETER
I thought to use String.Split here, but it either converts everything to uppercase, or throw me an index out of bounds exception.
This is what I've tried:
Code:
Private Sub AppCAPITALISE(ByVal strName As String, ByVal intNameIndex As Integer) 'sub to convert & display end result
Dim stArAppFName As String()
stArAppFName = strName.Split(" ", intNameIndex)
For intTemp As Integer = 0 To intNameIndex
txtAppFullNames.Text = stArAppFName(intTemp).ToUpper
Next intTemp
End Sub
Private Sub rdFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdFirst.Click, rdSecond.Click, rdThird.Click, rdFourth.Click 'how many names?
Select Case DirectCast(sender, RadioButton).Name
Case "rdFirst"
shAppCAP = 1
Case "rdSecond"
shAppCAP = 2
Case "rdThird"
shAppCAP = 3
Case "rdFourth"
shAppCAP = 4
End Select
AppCAPITALISE(strFullNames, shAppCAP)
End Sub
Private Sub txtAppFullNames_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAppFullNames.LostFocus 'store text entered
If Not txtAppFullNames.Text = String.Empty Then strFullNames = txtAppFullNames.Text
End Sub
The variables I used were:
Code:
Private shAppCAP As Short
Private strFullNames As String
Can anyone help me format the names appropriately, please?