Here is very simple code to uppercase the first letter of each word in a string.
What i have done in this code is stored all the words into an array. Then by looping through the array the word is being split in two, the first part of the substring is the first letter. The first letter is then capitalized. After that is done the word is joined back together to make a whole. This process is done for every word in the array. As the process takes action the new edited word replaces the old word in the same array. The words from the array are being placed on a single line which will become the new value of Textbox1.
vb Code:
'Try something like so: Dim words() As String words = TextBox1.Text.Split(" "c) For x As Integer = 0 To words.Rank + 1 words(x) = (words(x).Substring(0, 1).ToUpper & words(x).Substring(1, words(x).Length - 1)) Next Dim NewString As String = String.Empty For i As Integer = 0 To words.Rank + 1 If i = 0 Then NewString = (words(i)) Else NewString = (NewString & " " & words(i)) End If Next TextBox1.Text = NewString
EDIT: Here is an even simpilar code that will produce the same result as my code above.
vb Code:
MyString = Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(MyString)




Reply With Quote