|
-
Feb 14th, 2009, 07:42 PM
#1
Thread Starter
New Member
Uppercase letters in a string
Hi, can anyone tell me how to take a name entered in a text box and convert only the first letter of each name to upper and then convert the rest to lower.
Ex: "john doe" --> "John Doe"
"jAkE sMiTh" --> "Jake Smith"
Thanks.
-
Feb 14th, 2009, 08:06 PM
#2
Frenzied Member
Re: Uppercase letters in a string
I think there is a simpilar way to do this but in the mean time here.
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
Last edited by noahssite; Feb 14th, 2009 at 08:11 PM.
-
Feb 14th, 2009, 08:11 PM
#3
Thread Starter
New Member
Re: Uppercase letters in a string
Thanks I'll give it a shot.
-
Feb 14th, 2009, 08:18 PM
#4
Re: Uppercase letters in a string
Try this;
Code:
MyString = Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(MyString)
-
Feb 14th, 2009, 08:23 PM
#5
Frenzied Member
Re: Uppercase letters in a string
 Originally Posted by Bulldog
Try this;
Code:
MyString = Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(MyString)
lol, well there's putting it in one line. I guess i should remove the link i put in my signature...lol
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|