首页 > Windows开发 > 详细

C#隐私字符替换

时间:2017-07-09 09:29:56      阅读:279      评论:0      收藏:0      [点我收藏+]
class Program
    {
        static void Main(string[] args)
        {

            string str = ReplaceWithSpecialChar("221282188801019662", 4, 4);
            Console.WriteLine(str);
            Console.ReadKey();
        }

        /// <summary>
        /// 将传入的字符串中间部分字符替换成特殊字符
        /// </summary>
        /// <param name="value">需要替换的字符串</param>
        /// <param name="startLen">前保留长度</param>
        /// <param name="endLen">尾保留长度</param>
        /// <param name="replaceChar">特殊字符</param>
        /// <returns>被特殊字符替换的字符串</returns>
        private static string ReplaceWithSpecialChar(string value, int startLen = 4, int endLen = 4, char specialChar = *)
        {
            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;
        }
    }

 

C#隐私字符替换

原文:http://www.cnblogs.com/qzxj/p/7140471.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!