عند العمل في المشاريع ، غالبًا ما تواجه بعض المشكلات التي تحتاجها للحكم على ما إذا كانت الشخصيات صينية ، لذلك قمت بجمع مقتطفات رمز للحكم على الشخصيات الصينية. إليك بعض المشاركة للرجوع إليها.
لقد نشرت الرمز مباشرة ، مع تعليقات مفصلة فيه.
package com.coder4j.main ؛ استيراد java.util.regex.pattern ؛/*** جافا القضاة الأحرف الصينية** Author Chinaxiang* date 2015-08-11 ** "مرحبًا ، توم.!@#$ ٪^&*() _+-= {} | [] ؛ ':/"؟ " "╃" ؛ String S8 = "╂" ؛ // السلسلة الصينية التقليدية S9 = "Old" ؛ // 1 استخدام نطاق الأحرف لتحديد ما إذا كان system.out.println ("S1 يحتوي على الصينية:" + Has ChineseByRange (S1)) ؛ الصينية: " + له صيني BRANGE (S3)) ؛ // truestystem.out.println (" S4 يحتوي على الصينية: " + Have alearybyrange (S4)) ؛ // falsystem.out.println (" S5 يحتوي على الصينية: " + HazedRange (S5)) ؛ صيني brange (S6)) ؛ // falsystem.out.println ("S7 يحتوي على صينية:" + له صينية (S7)) ؛ trueSystem.out.println ("-------------------") ؛ System.out.println ("S1 كلها صينية:" + ishareByrange (S1)) ؛ // falsystem.out.println ("S2 كلها صينية:" + صينية brange (S2)) ؛ System.out.println ("S4 كل الصينية:" + IschineseByrange (S4)) ؛ // falsystem.out.println ("S5 كلها صينية:" + ischinesebyrange (S5)) ؛ falsystem.out.println ("S7 كلها صينية:" + IschineseByrange (S7)) ؛ // falsystem.out.println ("S8 كلها صينية:" + Ischinesebyrange (S8)) ؛ trueSystem.out.println ("---------------") ؛ // 2 استخدام نطاق الحرف الحكم العادي (والنتيجة هي نفس system.out.println ("S1 يحتوي على الصينية:" + HazedByreg (S1)) ؛ trueSystem.out.println ("S3 يحتوي على اللغة الصينية:" + has asharebreg (s3)) ؛ // truestystem.out.println ("S4 يحتوي الصينية: " + له صيني بيريج (S6)) ؛ // falsystem.out.println (" S7 يحتوي على صينية: " + Have ChineseByreg (S7)) ؛ // falsystem.out.println (" S8 Conneshing: " + has inchineByreg (s8)) ؛ // falsystem.out.println ( trueSystem.out.println ("-------------------") ؛ System.out.println ("S1 كلها صينية:" + ishareBreg (S1)) ؛ // falsystem.out.println ("S2 كلها صينية:" + صينية (S2)) System.out.println ("S4 كلها صينية:" + IschineseByreg (S4)) ؛ // falsystem.out.println ("S5 كلها صينية:" + Ischinesebyreg (S5)) ؛ // falsystem.out.println ("S6 كل الصينية:" falsystem.out.println ("S7 كلها صينية:" + ischinesebyreg (S7)) ؛ // falsystem.out.println ("S8 كلها صينية:" + Ischinesebyreg (s8)) ؛ trueSystem.out.println ("------------------") ؛ // 3 استخدم حرف CJK لتحديد ما إذا كان System.out.println ("S1 يحتوي على الصينية:" + haschinese (s1)) ؛ " + له صيني (S3)) ؛ // trueSystem.out.println (" S4 يحتوي على الصينية: " + له الصينية (S4)) ؛ // falsystem.out.println (" S5 يحتوي على الصينية: " + له الصينية (S5)) ؛ falsystem.out.println ("S7 يحتوي على اللغة الصينية:" + له الصينية (S7)) ؛ // falsystem.out.println ("S8 يحتوي trueSystem.out.println ("---------------------") ؛ System.out.println ("S1 كلها صينية:" + Ischinese (S1)) ؛ // falsystem.out.println ("S2 كل الصينية:" + ischinese (S2)) ؛ Ischinese (S3)) ؛ // تم تضمين علامات الترقيم الصينية الحقيقية أيضًا في system.out.println ("S4 كلها صينية:" + Ischinese (S4)) ؛ falsystem.out.println ("S7 كلها صينية:" + Ischinese (S7)) ؛ // falsystem.out.println ("S8 كلها صينية:" + Ischinese (S8)) ؛ // يحتوي على علامات الترقيم الصينية <br>** param str* @return*/public static boolean لها الصينية (سلسلة str) {if (str == null) {return false ؛ param str* @return*/public static boolean ischinese (string str) {if (str == null) {return false ؛ @return*/private static boolean ischinese (char c) {character.unicodeblock ub = character.unicodeblock.of (c) ؛ if (ub == character.unicodeblock.cjk_unified_ideographs) {return true ؛ character.unicodeblock.cjk_symbols_and_punctuation) {return true ؛} آخر إذا (ub == character.unicodeblock.cjk_unified_ideographs_extension_a) {return true ؛ character.unicodeblock.cjk_unified_ideographs_extense_c) {return true ؛} آخر إذا (ub == character.unicodeblock.cjk_unified_ideographs_extense_d) {return true ؛ character.unicodeblock.halfwidth_and_fullwidth_forms) {return true ؛} return false ؛}/*** ما إذا كانت الأحرف الصينية مدرجة <br>* القاضي بناءً على نطاق الترميز من الأحرف الصينية <br>* cjk unifed strupe (لا تشمل الصينيين ، 《》 () "،! str) {if (str == null) {return false ؛} نمط نمط = pattern.compile ("[// u4e00-// u9fbf]+") ! ¥ والرموز الأخرى) <br>** param str* @return*/public static boolean ischinesebyreg (string str) {if (str == null) {return false ؛} نمط نمط = pattern.compile ("[// u4e00-// u9fbf]+") ؛ ترميز نطاق الأحرف الصينية <br>* CJK Unified Chinesion (لا يشمل الصينية ، "《》 ()" '' '،! ¥ والرموز الأخرى) <br>** @param str* @return*/public static boolean have inchankbyrange (for string str) {if (str == null) 0x4e00 && c <= 0x9fbf) {return true ؛}} return false ؛}/*** ما إذا كانت جميع الأحرف الصينية هي أحرف صينية <br>* القاضي استنادًا إلى نطاق تشفير الأحرف الصينية <br>* cjk unide string*/public string string ، "" "'' '' ،! {if (str == null) {return false ؛} char [] ch = str.tochararray () ؛ for (char c: ch) {if (c <0x4e00 || c> 0x9fbf) {return false ؛}} return true ؛}}}}}إذا كنت تحكم فقط على ما إذا كانت صينية دون الحكم على علامات الترقيم الصينية ، فمن المستحسن استخدام المطابقة المنتظمة ، والتي قد تكون أكثر كفاءة.
يقدم لك Code Condition أعلاه رمز Java على سبيل المثال للحكم على الشخصيات على أنها صينية (مفيدة للغاية) ، وآمل أن يكون ذلك مفيدًا لك.