[代码] java代码
004 | * @param str String 原始字符串 |
005 | * @param splitsign String 分隔符 |
006 | * @return String[] 分割后的字符串数组 |
008 | @SuppressWarnings("unchecked") |
009 | public static String[] split(String str, String splitsign) { |
011 | if (str == null || splitsign == null) |
013 | ArrayList al = new ArrayList(); |
014 | while ((index = str.indexOf(splitsign)) != -1) { |
015 | al.add(str.substring(0, index)); |
016 | str = str.substring(index + splitsign.length()); |
019 | return (String[]) al.toArray(new String[0]); |
025 | * @param from String 原始字符串 |
026 | * @param to String 目标字符串 |
027 | * @param source String 母字符串 |
028 | * @return String 替换后的字符串 |
030 | public static String replace(String from, String to, String source) { |
031 | if (source == null || from == null || to == null) |
033 | StringBuffer bf = new StringBuffer(""); |
035 | while ((index = source.indexOf(from)) != -1) { |
036 | bf.append(source.substring(0, index) + to); |
037 | source = source.substring(index + from.length()); |
038 | index = source.indexOf(from); |
041 | return bf.toString(); |
045 | * 替换字符串,能能够在HTML页面上直接显示(替换双引号和小于号) |
047 | * @param str String 原始字符串 |
048 | * @return String 替换后的字符串 |
050 | public static String htmlencode(String str) { |
055 | return replace("/"", """, replace("<", "<", str)); |
059 | * 替换字符串,将被编码的转换成原始码(替换成双引号和小于号) |
064 | public static String htmldecode(String str) { |
069 | return replace(""", "/"", replace("<", "<", str)); |
072 | private static final String _BR = "<br/>"; |
075 | * 在页面上直接显示文本内容,替换小于号,空格,回车,TAB |
077 | * @param str String 原始字符串 |
078 | * @return String 替换后的字符串 |
080 | public static String htmlshow(String str) { |
085 | str = replace("<", "<", str); |
086 | str = replace(" ", " ", str); |
087 | str = replace("/r/n", _BR, str); |
088 | str = replace("/n", _BR, str); |
089 | str = replace("/t", " ", str); |
096 | * @param str String 字符串 |
097 | * @param length int 指定长度 |
098 | * @return String 返回的字符串 |
100 | public static String toLength(String str, int length) { |
108 | if (str.getBytes("GBK").length <= length) { |
111 | } catch (Exception ex) { |
113 | StringBuffer buff = new StringBuffer(); |
119 | c = str.charAt(index); |
130 | return buff.toString(); |
137 | * @return 是整数返回true,否则返回false |
139 | public static boolean isInteger(String str) { |
140 | Pattern pattern = Pattern.compile("^[-//+]?[//d]*$"); |
141 | return pattern.matcher(str).matches(); |
145 | * 判断是否为浮点数,包括double和float |
148 | * @return 是浮点数返回true,否则返回false |
150 | public static boolean isDouble(String str) { |
151 | Pattern pattern = Pattern.compile("^[-//+]?[.//d]*$"); |
152 | return pattern.matcher(str).matches(); |
156 | * 判断输入的字符串是否符合Email样式. |
159 | * @return 是Email样式返回true,否则返回false |
161 | public static boolean isEmail(String str) { |
162 | Pattern pattern = Pattern.compile("^//w+([-+.]//w+)*@//w+([-.]//w+)*//.//w+([-.]//w+)*$"); |
163 | return pattern.matcher(str).matches(); |
170 | * @return 如果是纯汉字返回true,否则返回false |
172 | public static boolean isChinese(String str) { |
173 | Pattern pattern = Pattern.compile("[/u0391-/uFFE5]+$"); |
174 | return pattern.matcher(str).matches(); |
183 | public static boolean isBlank(String str) { |
184 | return str == null || str.trim().length() == 0; |
191 | public static boolean isHandset(String handset) { |
193 | if(!handset.substring(0,1).equals("1")) { |
196 | if (handset==null || handset.length()!=11) { |
199 | String check = "^[0123456789]+$"; |
200 | Pattern regex = Pattern.compile(check); |
201 | Matcher matcher = regex.matcher(handset); |
202 | boolean isMatched = matcher.matches(); |
208 | } catch (RuntimeException e) { |
|
|