You can read-modify-write, or try this alternative:
With TextBox1
If .TextLength >= 4 Then
.SelectionStart = 3
.SelectionLength = 1
.SelectedText = "*"
End If
End With
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi All,
I am using VB.NET 2019.
I have a Text box control on a form that holds a string, how can I change one character in that string at a specified position using code? For example, suppose the control holds a string of characters like "ABCDE" and I want to change the character at position 4 to an asterisk so that it would then be "ABC*E".
Peter Hibbs.
You can read-modify-write, or try this alternative:
With TextBox1
If .TextLength >= 4 Then
.SelectionStart = 3
.SelectionLength = 1
.SelectedText = "*"
End If
End With
Hi Viorel-1
OK, thanks, that works but is this the simplest method to do this? In VBA it can be done with the MID function in one line of code. I would have thought that VB.NET would have something similar, but maybe not! Perhaps it will be possible to build a user defined function which emulates the MID function, I will have to think about it.
Anyway, thanks again.
Peter Hibbs.