Results 1 to 5 of 5

Thread: Uppercase letters in a string

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    6

    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.

  2. #2
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    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:
    1. 'Try something like so:
    2.         Dim words() As String
    3.         words = TextBox1.Text.Split(" "c)
    4.         For x As Integer = 0 To words.Rank + 1
    5.             words(x) = (words(x).Substring(0, 1).ToUpper & words(x).Substring(1, words(x).Length - 1))
    6.         Next
    7.         Dim NewString As String = String.Empty
    8.         For i As Integer = 0 To words.Rank + 1
    9.             If i = 0 Then
    10.                 NewString = (words(i))
    11.             Else
    12.                 NewString = (NewString & " " & words(i))
    13.             End If
    14.         Next
    15.         TextBox1.Text = NewString
    Last edited by noahssite; Feb 14th, 2009 at 08:11 PM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    6

    Re: Uppercase letters in a string

    Thanks I'll give it a shot.

  4. #4
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: Uppercase letters in a string

    Try this;

    Code:
    MyString = Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(MyString)

  5. #5
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: Uppercase letters in a string

    Quote 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
  •  



Click Here to Expand Forum to Full Width