字符串处理类

时间:2020-11-27 13:22:49
【文件属性】:
文件名称:字符串处理类
文件大小:2KB
文件格式:CS
更新时间:2020-11-27 13:22:49
字符串处理 关键字查找 public class StringHelper { /// /// 是否包含字符串,可以直接. /// /// 字符串. /// 被查找的字符串. /// public static bool Contains(string text, string patten) { //去掉收尾的扩展“%”字符 if (string.IsNullOrEmpty(patten) && string.IsNullOrEmpty(text)) return true; if (string.IsNullOrEmpty(patten) || string.IsNullOrEmpty(text)) return false; patten = patten.Trim().Trim('%'); var lenStr = patten.Length; if (!patten.Contains("%")) return text.Contains(patten); var sArray = patten.Split('%'); return SearchKeywords(text, sArray); } /// /// 查询关键字方法 /// /// 原字符串 /// 关键字列表用|分开 /// 如果存在关键字返回true,反之返回false。 public static bool SearchKeywords(string source, string[] keywords) { return keywords.All(source.Contains); } /// /// 字符串分割方法. /// /// The source. /// The keyword. /// List<System.String>. public static List StringSplit(string source, string keyword) { if (string.IsNullOrEmpty(keyword)) return new List {source}; var list = new List(source.Split(new[] {keyword}, StringSplitOptions.RemoveEmptyEntries)); return list; } }

网友评论