C # Privacy Information (bank account, ID number, name) middle part special character substitution (*)

Source: Internet
Author: User

Recently done a functional module on the bank, the need to use the middle portion of the Privacy Information bank to replace, so write down, the following code:

        <summary>////To replace the passed-in middle part character with a special character///</summary>//<param name= "value" & gt; string to be replaced </param>//<param name= "Startlen" > Pre-reserved length </param>//<param name= "Endlen" &G t; tail retention length </param>//<param name= "Replacechar" > Special characters </param>//<returns> strings replaced by special characters & lt;/returns> private static string Replacewithspecialchar (string value, int startlen = 4, int endlen = 4, char s Pecialchar = ' * ') {try {int lenth = value.                Length-startlen-endlen; String replacestr = value.                Substring (Startlen, lenth); String specialstr = String.                Empty;                for (int i = 0; i < replacestr.length; i++) {specialstr + = Specialchar; } value = value.            Replace (Replacestr, SPECIALSTR); } catch (Exception) {throW        } return value; }

  

The invocation and effect are as follows:

Replacewithspecialchar ("Collian Stay", 1, 0, ' * ')-->result: Ke * stay

Replacewithspecialchar ("622212345678485")-->result:6222*******8485

Replacewithspecialchar ("622212345678485", 4, 4, ' * ')-->result:6222*******8485

Note: If the incoming Startlen/endlen exceeds the string length, an subscript out-of-bounds exception will be thrown

Just began to write blog, presentation, naming norms, technical content are still lacking, I hope you have more guidance, thank you!!!

 

C # Privacy Information (bank account, ID number, name) middle part special character substitution (*)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.