.net工具类——删除最后结尾的一个逗号

.net工具类——删除最后结尾的一个逗号

  1. DelLastComma:删除最后结尾的一个逗号
  2. DelLastChar:删除最后结尾的指定字符后的字符

 

        #region 删除最后结尾的一个逗号

        /// <summary>
        /// 删除最后结尾的一个逗号
        /// </summary>
        public static string DelLastComma(string str)
        {
            if (str.Length < 1)
            {
                return "";
            }
            return str.Substring(0, str.LastIndexOf(","));
        }

        #endregion 删除最后结尾的一个逗号

        #region 删除最后结尾的指定字符后的字符

        /// <summary>
        /// 删除最后结尾的指定字符后的字符
        /// </summary>
        public static string DelLastChar(string str, string strchar)
        {
            if (string.IsNullOrEmpty(str))
                return "";
            if (str.LastIndexOf(strchar) >= 0 && str.LastIndexOf(strchar) == str.Length - 1)
            {
                return str.Substring(0, str.LastIndexOf(strchar));
            }
            return str;
        }

        #endregion 删除最后结尾的指定字符后的字符

 

posted @ 2020-08-13 14:24  小确幸123  阅读(514)  评论(0编辑  收藏  举报