3.7
fxl
2023-03-07 632a18ee7c83441a6036b90577424d2daad8d19c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package com.hxzkoa.util;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
 
/**
 * 字符串工具类
 * @author 
 *
 */
public class StringUtil2 {
 
 
    /**
     * 判断是否是空
     * @param str
     * @return
     */
    public static boolean isEmpty(String str){
        if(str==null||"".equals(str.trim())){
            return true;
        }else{
            return false;
        }
    }
    
    /**
     * 判断是否不是空
     * @param str
     * @return
     */
    public static boolean isNotEmpty(String str){
        if((str!=null)&&!"".equals(str.trim())){
            return true;
        }else{
            return false;
        }
    }
    
    /**
     * 格式化模糊查询
     * @param str
     * @return
     */
    public static String formatLike(String str){
        if(isNotEmpty(str)){
            return "%"+str+"%";
        }else{
            return null;
        }
    }
    
    /**
     * 过滤掉集合里的空格
     * @param list
     * @return
     */
    public static List<String> filterWhite(List<String> list){
        List<String> resultList=new ArrayList<String>();
        for(String l:list){
            if(isNotEmpty(l)){
                resultList.add(l);
            }
        }
        return resultList;
    }
    
    /**
     * 去除html标签
     */
    public static String stripHtml(String content) { 
        // <p>段落替换为换行 
        content = content.replaceAll("<p .*?>", "\r\n"); 
        // <br><br/>替换为换行 
        content = content.replaceAll("<br\\s*/?>", "\r\n"); 
        // 去掉其它的<>之间的东西 
        content = content.replaceAll("\\<.*?>", ""); 
        // 去掉空格 
        content = content.replaceAll(" ", ""); 
        return content;   
    }
    
    /**
     * 生成六位随机数
     * @return
     */
    public static String genSixRandomNum(){
        Random random = new Random();
        String result="";
        for (int i=0;i<6;i++)
        {
            result+=random.nextInt(10);
        }
        return result;
    }
 
    /**
     * 生成由[A-Z,0-9]生成的随机字符串
     * @param length  欲生成的字符串长度
     * @return
     */
    public static String getRandomString(int length){
        Random random = new Random();
 
        StringBuffer sb = new StringBuffer();
 
        for(int i = 0; i < length; ++i){
            int number = random.nextInt(2);
            long result = 0;
 
            switch(number){
                case 0:
                    result = Math.round(Math.random() * 25 + 65);
                    sb.append(String.valueOf((char)result));
                    break;
                case 1:
 
                    sb.append(String.valueOf(new Random().nextInt(10)));
                    break;
            }
        }
        return sb.toString();
    }
 
 
}