c#字符串操作辅助类
/**/
/// <summary>
/// 字符串操作辅助类
/// </summary>
public class StringUtil
{
一些基本的符号常量
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;
}
}
本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/xiexiaokui/archive/2008/07/19/1246567.html,如需转载请自行联系原作者