【蛻變之路】第46天 字符串校驗與SQL查詢(2019年10月26日)

    Hello,大家好!我是程序員阿飛!今天主要給大家分享一下上週項目中遇見的字符串校驗以及多個重複字段只保留一條數據的SQL寫法。

    一、判斷字符串是否爲漢字

        1、判斷字符串是否包含漢字   

        public boolean checkcountname(String countname)

            {

                 Pattern p = Pattern.compile("[\u4e00-\u9fa5]");

                    Matcher m = p.matcher(countname);

                    if (m.find()) {

                        return true;

                    }

                    return false;

          }

        2、判斷字符串是否都是由漢字組成

        public boolean checkname(String name)

            {

                int n = 0;

                for(int i = 0; i < name.length(); i++) {

                    n = (int)name.charAt(i);

                    if(!(19968 <= n && n <40869)) {

                        return false;

                    }

                }

                return true;

            }

        3、參考網址:https://blog.csdn.net/changjiale110/article/details/78915969

    二、UUID的校驗

        1、生產UUID的方法     

        public static UUID getRandomUUID(String str) {

            // 產生UUID

            if (str == null) {

                return UUID.randomUUID();

            } else {

            return UUID.nameUUIDFromBytes(str.getBytes());

            }

        }

        2、判斷是否爲UUID        

        public static boolean isValidUUID(String uuid) {

            // UUID校驗

            if (uuid == null) {

                System.out.println("uuid is null");

            }

            String regex = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";

            if (uuid.matches(regex)) {

                return true;

            }

            return false;

        }

        3、參考網址:https://blog.csdn.net/Kangyucheng/article/details/86498341

    三、SQL多個重複字段只保留一條數據

        SELECT * FROM test1 GROUP BY  factory_name,model_name,hard_version HAVING count(*)>=1

    參考網址:https://blog.csdn.net/sxf_123456/article/details/77509201

    四、分享時刻

        1、https://u.tools/

    2、https://cloudstudio.net/

    3、http://yearning.io/





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章