字符串移除前后指定字符
2015-04-09 16:03:03 访问(2654) 赞(0) 踩(0)
/// <summary>
/// 字符串移除前后指定字符
/// </summary>
/// <param name="str"></param>
/// <param name="strChar"></param>
/// <returns></returns>
public string StringRemoveChar(string str, string strChar)
{
if (str == null || str.Length == 0)
return "";
if (strChar == null || strChar.Length == 0)
return str;
while (true)
{
if (!str.StartsWith(strChar))
break;
str = str.Substring(1);
if (str.Length == 0)
return "";
}
while (true)
{
if (!str.EndsWith(strChar))
break;
str = str.Substring(0, str.Length - 1);
if (str.Length == 0)
return "";
}
return str;
}
标签:
字符串移除前后指定字符 


上一条:
下一条:
相关评论
发表评论