Code /**//**/ /**//// <summary> /// 字符串操作辅助类 /// </summary> public class StringUtil { 一些基本的符号常量#region 一些基本的符号常量 /**//**/ /**//// <summary> /// 点符号 . /// </summary> public const string Dot = "."; /**//**/ /**//// <summary> /// 下划线 _ /// </summary> public const string UnderScore = "_"; /**//**/ /**//// <summary> /// 逗号加空格 , /// </summary> public const string CommaSpace = ", "; /**//**/ /**//// <summary> /// 逗号 , /// </summary> public const string Comma = ","; /**//**/ /**//// <summary> /// 左括号 ( /// </summary> public const string OpenParen = "("; /**//**/ /**//// <summary> /// 右括号 ) /// </summary> public const string ClosedParen = ")"; /**//**/ /**//// <summary> /// 单引号 ' /// </summary> public const string SingleQuote = "\'"; /**//**/ /**//// <summary> /// 斜线 \ /// </summary> public const string Slash = @"\"; #endregion private StringUtil() { } /**//**/ /**//// <summary> /// 移除空格并首字母小写的Camel样式 /// </summary> /// <param name="name"></param> /// <returns></returns> public static string ToCamel(string name) { string clone = name.TrimStart('_'); clone = RemoveSpaces(ToProperCase(clone)); return String.Format("{0}{1}", Char.ToLower(clone[0]), clone.Substring(1, clone.Length - 1)); } /**//**/ /**//// <summary> /// 移除空格并首字母大写的Pascal样式 /// </summary> /// <param name="name"></param> /// <returns></returns> public static string ToCapit(string name) { string clone = name.TrimStart('_'); return RemoveSpaces(ToProperCase(clone)); } /**//**/ /**//// <summary> /// 移除最后的字符 /// </summary> /// <param name="s"></param> /// <returns></returns> public static string RemoveFinalChar(string s) { if (s.Length > 1) { s = s.Substring(0, s.Length - 1); } return s; } /**//**/ /**//// <summary> /// 移除最后的逗号 /// </summary> /// <param name="s"></param> /// <returns></returns> public static string RemoveFinalComma(string s) { if (s.Trim().Length > 0) { int c = s.LastIndexOf(","); if (c > 0) { s = s.Substring(0, s.Length - (s.Length - c)); } } return s; } /**//**/ /**//// <summary> /// 移除字符中的空格 /// </summary> /// <param name="s"></param> /// <returns></returns> public static string RemoveSpaces(string s) { s = s.Trim(); s = s.Replace(" ", ""); return s; } /**//**/ /**//// <summary> /// 字符串首字母大写 /// </summary> /// <param name="s"></param> /// <returns></returns> public static string ToProperCase(string s) { string revised = ""; if (s.Length > 0) { if (s.IndexOf(" ") > 0) { revised = Strings.StrConv(s, VbStrConv.ProperCase, 1033); } else { string firstLetter = s.Substring(0, 1).ToUpper(new CultureInfo("en-US")); revised = firstLetter + s.Substring(1, s.Length - 1); } } return revised; } /**//**/ /**//// <summary> /// 判断字符是否NULL或者为空 /// </summary> public static bool IsNullOrEmpty(string value) { if (value == null || value == string.Empty) { return true; } return false; } }