.net工具類——刪除最後結尾的一個逗號
阿新 • • 發佈:2020-08-13
.net工具類——刪除最後結尾的一個逗號
- DelLastComma:刪除最後結尾的一個逗號
- 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刪除最後結尾的指定字元後的字元