Hi i want to convert only the first letter of a firstname n his lastname seperating by a space. Note every time he/she input firstname the first letter should be Uppercase and when she/he press the space bar the last name only the first letter should be Uppercase.
Help Me Plzzzz
Ex:
Geeta Lopez

Dani AI

Generated

Both suggestions in this thread are valid paths. gave a simple manual-char approach that yields precise control, while pointed out the built-in proper-case helper that is the quickest one-liner for many simple names. Important trade-offs: the built-in helpers will title-case every word (and often lowercase the rest) which is fine for ordinary input but may mishandle intentional or culture-specific casing (hyphens, Mc/Mac, O' prefixes, all-caps acronyms, non-Latin scripts).

Formatting is best applied when the field loses focus (LostFocus/Leave) to avoid disrupting typing, breaking Undo, or moving the caret unexpectedly. When live formatting is required, preserve the caret and avoid reentrancy by comparing the transformed text with the current text before assigning.

Example VB.NET pattern (culture-aware TitleCase with caret preservation):

Imports System.Globalization

Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox1.TextChanged
    Dim tb As TextBox = DirectCast(sender, TextBox)
    Dim selStart As Integer = tb.SelectionStart

    Dim ti As TextInfo = CultureInfo.CurrentCulture.TextInfo
    Dim newText As String = ti.ToTitleCase(tb.Text.ToLower())

    If newText <> tb.Text Then
        tb.Text = newText
        tb.SelectionStart = Math.Min(selStart, tb.Text.Length)
    End If
End Sub

Edge cases to test and handle explicitly: multiple spaces, leading/trailing spaces, hyphenated surnames (Smith-Jones), apostrophes (O'Neill), particles (van, de) and initials or acronyms (NASA). For strict first-name/last-name behavior only, split on the first space and title-case just those two tokens. For enterprise rules (Mc/Mac, special prefixes), add targeted string rules after the general transformation. For simple scenarios the built-in proper-case helper mentioned by is fine; for robust, culture-aware behavior use TextInfo or a controlled manual routine as shown above.

Recommended Answers

All 2 Replies

private string MakeFirstUpperMakePascalCase( string name )

{ if ( name.Length <= 1) return name.ToUpper(); return Char.ToUpper( name[0] ).ToString() + name.Substring( 1 ); Char[] letters = name.ToCharArray(); letters[0] = Char.ToUpper( letters[0] ); return new string( letters );}

Mr. Ramesh has given very best way/solution, but there is an easy way for that.
There is one function called StrConv it can be used to do your required stuf only in one line code. which is as follow.
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)
End Sub
End Class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.