[英]Enable Password Char in TextBox except last N character / Limit Masked Char
How to enable Password Char in TextBox except last N character? 如何在TextBox中启用除最后N个字符以外的密码字符?
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.. 但它很难操纵,我会在
Keypress
, TextChange
等每个事件中传递原始卡值。
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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.