1. 程式人生 > 實用技巧 >.net工具類——刪除最後結尾的一個逗號

.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
刪除最後結尾的指定字元後的字元