diff --git a/README.MD b/README.MD index 92458cb..fb1820c 100644 --- a/README.MD +++ b/README.MD @@ -26,13 +26,13 @@ golang版本已移植了`StringSearch`、`StringSearchEx`、`WordsSearch`、`Wor ``` csharp // 转成简体 - WordsHelper.ToSimplifiedChinese("壹佰贰拾叁億肆仟伍佰陆拾柒萬捌仟玖佰零壹元壹角贰分"); - WordsHelper.ToSimplifiedChinese("壹佰贰拾叁億肆仟伍佰陆拾柒萬捌仟玖佰零壹元壹角贰分",1);// 港澳繁体 转 简体 - WordsHelper.ToSimplifiedChinese("壹佰贰拾叁億肆仟伍佰陆拾柒萬捌仟玖佰零壹元壹角贰分",2);// 台湾正体 转 简体 + WordsHelper.ToSimplifiedChinese("我愛中國"); + WordsHelper.ToSimplifiedChinese("我愛中國",1);// 港澳繁体 转 简体 + WordsHelper.ToSimplifiedChinese("我愛中國",2);// 台湾正体 转 简体 // 转成繁体 - WordsHelper.ToTraditionalChinese("壹佰贰拾叁亿肆仟伍佰陆拾柒万捌仟玖佰零壹元壹角贰分"); - WordsHelper.ToTraditionalChinese("壹佰贰拾叁亿肆仟伍佰陆拾柒万捌仟玖佰零壹元壹角贰分",1);// 简体 转 港澳繁体 - WordsHelper.ToTraditionalChinese("壹佰贰拾叁亿肆仟伍佰陆拾柒万捌仟玖佰零壹元壹角贰分",2);// 简体 转 台湾正体 + WordsHelper.ToTraditionalChinese("我爱中国"); + WordsHelper.ToTraditionalChinese("我爱中国",1);// 简体 转 港澳繁体 + WordsHelper.ToTraditionalChinese("我爱中国",2);// 简体 转 台湾正体 // 转成全角 WordsHelper.ToSBC("abcABC123"); // 转成半角 diff --git a/csharp/ToolGood.Words/WordsHelper.cs b/csharp/ToolGood.Words/WordsHelper.cs index bd4ff3d..6f0ea93 100644 --- a/csharp/ToolGood.Words/WordsHelper.cs +++ b/csharp/ToolGood.Words/WordsHelper.cs @@ -150,26 +150,26 @@ namespace ToolGood.Words #region 判断输入是否为中文 /// - /// 判断输入是否为中文 ,中文字符集为[0x4E00,0x9FA5] + /// 判断输入是否为中文 ,中文字符集为[0x4E00,0x9FA5][0x3400,0x4db5] /// /// /// public static bool HasChinese(string content) { - if (Regex.IsMatch(content, @"[\u4e00-\u9fa5]")) { + if (Regex.IsMatch(content, @"[\u3400-\u4db5\u4e00-\u9fd5]")) { return true; } else { return false; } } /// - /// 判断输入是否全为中文,中文字符集为[0x4E00,0x9FA5] + /// 判断输入是否全为中文,中文字符集为[0x4E00,0x9FA5][0x3400,0x4db5] /// /// /// public static bool IsAllChinese(string content) { - if (Regex.IsMatch(content, @"^[\u4e00-\u9fa5]*$")) { + if (Regex.IsMatch(content, @"^[\u3400-\u4db5\u4e00-\u9fd5]*$")) { return true; } else { return false; diff --git a/java/toolgood.words/README.MD b/java/toolgood.words/README.MD index a63445e..d147eb5 100644 --- a/java/toolgood.words/README.MD +++ b/java/toolgood.words/README.MD @@ -8,6 +8,33 @@ ToolGood.Words 目前java版本已移植了`StringSearch`、`StringSearchEx`、`WordsSearch`、`WordsSearchEx`、`IllegalWordsSearch`、`StringTypoSearch`、`NumberTypoSearch`及部分`WordsHelper` +## 繁体简体互换、全角半角互换、数字转成中文大写、拼音操作 +``` java + import toolgood.words.WordsHelper; + // 转成简体 + WordsHelper.ToSimplifiedChinese("我愛中國"); + WordsHelper.ToSimplifiedChinese("我愛中國",1);// 港澳繁体 转 简体 + WordsHelper.ToSimplifiedChinese("我愛中國",2);// 台湾正体 转 简体 + // 转成繁体 + WordsHelper.ToTraditionalChinese("我爱中国"); + WordsHelper.ToTraditionalChinese("我爱中国",1);// 简体 转 港澳繁体 + WordsHelper.ToTraditionalChinese("我爱中国",2);// 简体 转 台湾正体 + // 转成全角 + WordsHelper.ToSBC("abcABC123"); + // 转成半角 + WordsHelper.ToDBC("abcABC123"); + // 获取全拼 + WordsHelper.GetPinYin("我爱中国");//WoAiZhongGuo + WordsHelper.GetPinYin("我爱中国",true);//WǒÀiZhōngGuó + // 获取首字母 + WordsHelper.GetFirstPinYin("我爱中国");//WAZG + // 获取全部拼音 + WordsHelper.GetAllPinYin('传');//Chuan,Zhuan + // 获取姓名 + WordsHelper.GetPinYinForName("单一一")//ShanYiYi + WordsHelper.GetPinYinForName("单一一",true)//ShànYīYī +``` + ## 非法词(敏感词)检测(字符串搜索) 非法词(敏感词)检测类:`StringSearch`、`StringSearchEx`、`WordsSearch`、`WordsSearchEx`、`IllegalWordsSearch`、`StringTypoSearch`、`NumberTypoSearch`; @@ -25,40 +52,48 @@ ToolGood.Words ``` java - String test = "我是中国人"; - List list=new ArrayList(); - list.add("中国"); - list.add("国人"); - list.add("zg人"); - System.out.println("StringSearch run Test."); + import toolgood.words.IllegalWordsSearch; + import toolgood.words.IllegalWordsSearchResult; + import toolgood.words.StringSearch; + import toolgood.words.StringSearchEx; + import toolgood.words.WordsSearch; + import toolgood.words.WordsSearchEx; + import toolgood.words.WordsSearchResult; - StringSearch iwords = new StringSearch(); - iwords.SetKeywords(list); + String test = "我是中国人"; + List list=new ArrayList(); + list.add("中国"); + list.add("国人"); + list.add("zg人"); + System.out.println("StringSearch run Test."); - boolean b = iwords.ContainsAny(test); - if(b==false){ - System.out.println("ContainsAny is Error."); - } + StringSearch iwords = new StringSearch(); + iwords.SetKeywords(list); - String f = iwords.FindFirst(test); - if(f!="中国"){ - System.out.println("FindFirst is Error."); - } + boolean b = iwords.ContainsAny(test); + if(b==false){ + System.out.println("ContainsAny is Error."); + } - List all = iwords.FindAll(test); - if(all.get(0)!="中国"){ - System.out.println("FindAll is Error."); - } - if(all.get(1)!="国人"){ - System.out.println("FindAll is Error."); - } - if(all.size()!=2){ - System.out.println("FindAll is Error."); - } + String f = iwords.FindFirst(test); + if(f!="中国"){ + System.out.println("FindFirst is Error."); + } - String str = iwords.Replace(test, '*'); - if(str.equals("我是***")==false ){ - System.out.println("Replace is Error."); - } + List all = iwords.FindAll(test); + if(all.get(0)!="中国"){ + System.out.println("FindAll is Error."); + } + if(all.get(1)!="国人"){ + System.out.println("FindAll is Error."); + } + if(all.size()!=2){ + System.out.println("FindAll is Error."); + } + + String str = iwords.Replace(test, '*'); + if(str.equals("我是***")==false ){ + System.out.println("Replace is Error."); + } ``` \ No newline at end of file diff --git a/java/toolgood.words/src/main/java/toolgood/words/WordsHelper.java b/java/toolgood.words/src/main/java/toolgood/words/WordsHelper.java index 83214ae..53a80ef 100644 --- a/java/toolgood.words/src/main/java/toolgood/words/WordsHelper.java +++ b/java/toolgood.words/src/main/java/toolgood/words/WordsHelper.java @@ -203,7 +203,7 @@ public class WordsHelper { * @return */ public static boolean HasChinese(String content) { - return Pattern.matches("[\\u4e00-\\u9fa5]", content); + return Pattern.matches("[\\u3400-\\u4db5\\u4e00-\\u9fd5]", content); } /** @@ -213,7 +213,7 @@ public class WordsHelper { * @return */ public static boolean IsAllChinese(String content) { - return Pattern.matches("^[\\u4e00-\\u9fa5]*$", content); + return Pattern.matches("^[\\u3400-\\u4db5\\u4e00-\\u9fd5]*$", content); } /**