How to enable Password Char in TextBox except last N character?
I already tried this method
cardnumber.Select((c, i) => i < cardnumber.Length - 4 ? 'X' : c).ToArray()
But it is so hard to manipulate, I will pass original card value in every event like Keypress
,
TextChange
and etc..
Is there I way that is more simple and easy to managed?
This should do the trick,
string pw = "password1234";
char[] splitpw;
string cenpw;
int NtoShow;
splitpw = new char[pw.Length];
splitpw = pw.ToCharArray();
NtoShow = 4;
for (int i = 0; i < pw.Length; i++)
{
if (i < pw.Length - NtoShow)
cenpw += "*";
else
cenpw += splitpw[i];
}
//cenpw: "********1234"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With