Christian Quirante Christian Quirante - 2 years ago 59 Question

VB.Net (2008) How can I make the letters as PasswordChar "*" while retaining the first letter as the original?

I tried using this code

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox2.TextLength > 0 Then
For i As Integer = TextBox2.TextLength - 1 To 1 Step -1
TextBox2.Text = TextBox2.Text.Replace(TextBox2.Text.Substring(i, 1), "*")
End If
End Sub

But it didn't work out

I'm using textbox and my desired output is:
which is PASSWORD

Thanks in advance

Answer Source

For this you can use the Following Example:

Dim inputString As String = "Password"
inputString = inputString(0) + New String("*", inputString.Length - 1)

In your case inputString should be replaced with TextBox2.Text; Working Example Here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download