一、去除首尾字符串
///<summary>
/// 截前后字符(串)
///</summary>
///<param name="val">原字符串</param>
///<param name="str">要截掉的字符串</param>
///<param name="all">是否贪婪</param>
///<returns></returns>
private string GetString(string val,string str,bool all)
{
return Regex.Replace(val, @"(^(" + str + ")" + (all ? "*" : "") + "|(" + str + ")"+(all ? "*" : "") + "$)", "");
}
二、去除首尾字符
/// <summary>
///
/// </summary>
/// <param name="val">原字符串</param>
/// <param name="c">要截取的字符</param>
/// <returns></returns>
private string GetString(string val,char c)
{
return val.TrimStart(c).TrimEnd(c);
}