zoukankan      html  css  js  c++  java
  • 通用手机号、身份证号等隐藏显示方法

         /// <summary>
            /// 半隐藏显示,eg.传值:13112345678,4,4;结果:1311***5678。传值:13112345678,4,4,1,"&";结果:1311&5678。
            /// </summary>
            /// <param name="str">原字符串</param>
            /// <param name="beginShowStrLength">开始显示字符长度</param>
            /// <param name="endShowStrLength">结束显示字符串长度</param>
            /// <param name="replaceShowStrLength">替换后显示字符长度 默认:-1</param>
            /// <param name="replaceSymbol">替换后显示的字符,默认:*</param>
            /// <returns></returns>
            public static string Display(this string str, int beginShowStrLength, int endShowStrLength, int replaceShowStrLength = -1, string replaceSymbol = "*")
            {
                var length = str.Length - beginShowStrLength - endShowStrLength;
                replaceShowStrLength = replaceShowStrLength == -1 ? length : replaceShowStrLength;
                var stringBuilder = new StringBuilder();
                for (int i = 0; i < replaceShowStrLength; i++)
                {
                    stringBuilder.Append(replaceSymbol);
                }
                var replaceShowStr = stringBuilder.ToString();
                return Regex.Replace(str, "(\S{" + beginShowStrLength + "})\S{" + length + "}(\S{" + endShowStrLength + "})", "$1" + replaceShowStr + "$2");
            }
  • 相关阅读:
    33. Search in Rotated Sorted Array
    文章
    导航
    页眉和页脚
    渐变
    图像翻转与子画面
    背景图像定位
    背景图像
    使用css将图像居中
    使用CSS将图像对齐
  • 原文地址:https://www.cnblogs.com/flywing/p/8965969.html
Copyright © 2011-2022 走看看