var iwords = new StringSearch(); iwords.SetKeywords("中国|国人|zg人".Split('|')); bool contains = iwords.ContainsAny("我是中国人"); // true string replaced = iwords.Replace("我是中国人", '*'); // "我是***"
支持通配符的检测类
类名
特点
StringMatch / StringMatchEx
支持部分正则表达式语法,如 ., ?, [], `(
WordsMatch / WordsMatchEx
返回 WordsMatchResult,包含匹配词、原始词、位置等信息
示例代码
var wordsSearch = new WordsMatch(); wordsSearch.SetKeywords(".[中美]国|国人|zg人".Split('|')); var result = wordsSearch.FindFirst("我是中国人"); // result.Keyword => "是中国" // result.MatchKeyword => ".[中美]国"
var match = new PinyinMatch(); match.SetKeywords("北京|天津|河北|辽宁|吉林|黑龙江|山东|江苏|上海|浙江|安徽|福建|江西|广东|广西|海南|河南|湖南|湖北|山西|内蒙古|宁夏|青海|陕西|甘肃|新疆|四川|贵州|云南|重庆|西藏|香港|澳门|台湾".Split('|').ToList()); var result = match.Find("BJ"); // ["北京"]