会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
清山博客
慎言其余,则寡尤;多见阙殆,慎行其余,则寡悔。言寡尤,行寡悔。
博客园
首页
新随笔
联系
订阅
管理
StringHelper-字符串辅助类
using System; using System.Collections.Generic; using System.Text; using System.Globalization; using System.Text.RegularExpressions; namespace Framework { /// <summary> /// 字符串辅助类 /// </summary> public static class StringHelper { /// <summary> /// 截取字符串的后部分 /// </summary> /// <param name="source">原字符串</param> /// <param name="value">拆分字符串</param> /// <returns>截取后的字符串</returns> public static string SubstringAfter(this string source, string value) { if (string.IsNullOrEmpty(value)) { return source; } CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo; int index = compareInfo.IndexOf(source, value, CompareOptions.Ordinal); if (index < 0) { return string.Empty; } return source.Substring(index + value.Length); } /// <summary> /// 截取字符串的前部分 /// </summary> /// <param name="source">原字符串</param> /// <param name="value">拆分字符串</param> /// <returns>截取后的字符串</returns> public static string SubstringBefore(this string source, string value) { if (string.IsNullOrEmpty(value)) { return value; } CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo; int index = compareInfo.IndexOf(source, value, CompareOptions.Ordinal); if (index < 0) { return string.Empty; } return source.Substring(0, index); } /// <summary> /// 追加字符串,用分隔符分隔,默认分隔符为“,” /// </summary> /// <param name="sb">StringBulider对象</param> /// <param name="append">要追加的字符串</param> /// <param name="split">分隔符</param> public static void AppendString(this StringBuilder sb, string append, string split = ",") { if (sb.Length == 0) { sb.Append(append); return; } sb.Append(split); sb.Append(append); } /// <summary> /// 替换所有HTML标签为空 /// </summary> /// <param name="input">The string whose values should be replaced.</param> /// <returns>A string.</returns> public static string RemoveHtml(this string input) { var stripTags = new Regex("</?[a-z][^<>]*>", RegexOptions.IgnoreCase); return stripTags.Replace(input, string.Empty); } } }
posted @
2011-12-15 13:17
清山博客
阅读(
1121
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部
公告