问题描述
|
我有一个文本框,其中显示了信用卡或银行信息。我希望它被屏蔽(在page_load事件背后的代码中),以便用户可以看到类似以下内容:xxxxxxxxxxxx-9999。
例如:字串信用卡= 1234567812345678
我想这样显示:xxxxxxxxxxxx5678
谢谢!
解决方法
这样的事情可能适用于可变长度的文本:
// create 4 less x\'s than the credit card length.
// then append that to the last 4 characters of the credit card
new string(\'x\',creditcard.Length - 4) + creditcard.Substring(creditcard.Length - 4);
, \"xxxxxxxxxxxx\" + creditcard.Remove(0,12)
由于ISO / IEC 7812,信用卡号为16位数字。
如果信用卡不是ISO / IEC且具有其他长度,请使用greg的答案。像15位数字的AmEx和14位的Diner \。(我什至没有意识到这一点,因为在欧洲,AmEx并不常见。)