字符串操作辅助类

  **
  /// 字符串操作辅助类
  ///
  public class StringUtil
  {
  一些基本的符号常量#region 一些基本的符号常量
  /**
  /// 点符号 .
  ///
  public const string Dot = ".";
  /**
  /// 下划线 _
  ///
  public const string UnderScore = "_";
  /**
  /// 逗号加空格 ,
  ///
  public const string CommaSpace = ", ";
  /**
  /// 逗号 ,
  ///
  public const string Comma = ",";
  /**
  /// 左括号 (
  ///
  public const string OpenParen = "(";
  /**
  /// 右括号 )
  ///
  public const string ClosedParen = ")";
  /**
  /// 单引号 '
  ///
  public const string SingleQuote = "\'";
  /**
  /// 斜线 \
  ///
  public const string Slash = @"\";
  #endregion
  private StringUtil()
  {
  }
  /**
  /// 移除空格并首字母小写的Camel样式
  ///
  ///
  ///
  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));
  }
  /**
  /// 移除空格并首字母大写的Pascal样式
  ///
  ///
  ///
  public static string ToCapit(string name)
  {
  string clone = name.TrimStart('_');
  return RemoveSpaces(ToProperCase(clone));
  }
  /**
  /// 移除最后的字符
  ///
  ///
  ///
  public static string RemoveFinalChar(string s)
  {
  if (s.Length > 1)
  {
  s = s.Substring(0, s.Length - 1);
  }
  return s;
  }
  /**
  /// 移除最后的逗号
  ///
  ///
  ///
  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;
  }
  /**
  /// 移除字符中的空格
  ///
  ///
  ///
  public static string RemoveSpaces(string s)
  {
  s = s.Trim();
  s = s.Replace(" ", "");
  return s;
  }
  /**
  /// 字符串首字母大写
  ///
  ///
  ///
  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;
  }
  /**
  /// 判断字符是否NULL或者为空
  ///
  public static bool IsNullOrEmpty(string value)
  {
  if (value == null || value == string.Empty)
  {
  return true;
  }
  return false;
  }
  }
  字符串操作辅助类测试代码
  public class TestStringUtil
  {
  public static string Execute()
  {
  string value = "test String,";
  string result = string.Empty;
  result += "使用StringUtil字符串操作辅助类:" + "\r\n";
  result += "原字符串为:" + value + "\r\n";
  result += "StringUtil.IsNullOrEmpty:" + StringUtil.IsNullOrEmpty(value) + "\r\n";
  result += "StringUtil.ToCamel:" + StringUtil.ToCamel(value) + "\r\n";
  result += "StringUtil.ToCapit:" + StringUtil.ToCapit(value) + "\r\n";
  result += "StringUtil.RemoveSpaces:" + StringUtil.RemoveSpaces(value) + "\r\n";
  result += "StringUtil.RemoveFinalChar:" + StringUtil.RemoveFinalChar(value) + "\r\n";
  result += "StringUtil.ToProperCase:" + StringUtil.ToProperCase(value) + "\r\n";
  result += "\r\n\r\n";
  return result;
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值