标签:style blog http color os 2014 ar art
关键代码:
/// <summary> /// 移除字符串末尾指定字符 /// </summary> /// <param name="str">需要移除的字符串</param> /// <param name="value">指定字符</param> /// <returns>移除后的字符串</returns> public static string RemoveLastChar(this string str, string value) { int _finded = str.LastIndexOf(value); if (_finded != -1) { return str.Substring(0, _finded); } return str; }
单元测试:
[TestMethod()] public void RemoveLastCharTest() { string _testString = "YANZHIWEI。"; string _expected = "YANZHIWEI"; string _actual = StringToolV2.RemoveLastChar(_testString, "。"); Assert.AreEqual(_expected, _actual); }
测试结果:
希望有所帮助!
[C#]移除字符串末尾指定字符,布布扣,bubuko.com
标签:style blog http color os 2014 ar art
原文地址:http://www.cnblogs.com/Yan-Zhiwei/p/3904879.html