一個字符串處理的工具類(●’?’●)
包含以下功能:
判斷應(yīng)用程序是否安裝
字符拆分成數(shù)組
MD5 加密
拼接后的字符串
替換字符串
判斷多個參數(shù)是否都為空
將字符串轉(zhuǎn)換成HTML格式的字符串
將HTML格式的字符串轉(zhuǎn)換成常規(guī)顯示的字符串
獲取加密的手機號
檢查手機號
驗證固定電話號碼
檢查密碼有效
根據(jù)string.xml資源格式化字符串
驗證身份證號碼
將元單位數(shù)字轉(zhuǎn)成int類型的元
格式化數(shù)字
數(shù)字轉(zhuǎn)成以萬、億為單位,1.0–>1; 1.1–>1.1
將一字符串?dāng)?shù)組以某特定的字符串作為分隔來變成字符串
驗證字符串合法性
將數(shù)值型字符串轉(zhuǎn)換成Integer型
將數(shù)值型轉(zhuǎn)換成字符串
比較兩字符串大小(ASCII碼順序)
將阿拉伯?dāng)?shù)字的錢數(shù)轉(zhuǎn)換成中文方式
將字符串的首字母改為大寫
判斷l(xiāng)ist中是否包含某一個字符串
list轉(zhuǎn)String
String轉(zhuǎn)list 去除null 空串
根據(jù)Resource ID獲取字符串
將浮點數(shù)進行四舍五入
去除字符串前后的空格
去除轉(zhuǎn)義
添加url參數(shù)
設(shè)置一段不同顏色的文字
字符拆分
截取指定size的String
轉(zhuǎn)碼中文字符串
用來比較手機號版本
截取指定長度 從0開始,包左不包右
是否有中文字符
?
public class StringUtil { public static int DEFAULT_INT = -100; /** 判斷應(yīng)用程序是否安裝*/ public static boolean isPkgInstalled(String pkgName, Context context) { PackageInfo packageInfo = null; try { packageInfo = context.getPackageManager() .getPackageInfo(pkgName, 0); } catch (NameNotFoundException e) { packageInfo = null; e.printStackTrace(); } return packageInfo != null; } /** 字符拆分成數(shù)組*/ public static String getStrSplitByCondition(String str, String split, String condition) { String[] cookieArr = str.split(split); String result = ""; for (int i = 0; i < cookieArr.length; i++) { Log.i("ss", "___________________________cookieArr[" + i + "]:" + cookieArr[i]); if (cookieArr[i].contains(condition)) { Log.i("ss", "________________________________cookieArr[" + i + "]:" + cookieArr[i]); return cookieArr[i]; } } return result; } /** MD5 加密*/ public static String getSign(String signStr) { StringBuffer buf = new StringBuffer(""); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(signStr.getBytes()); byte b[] = md.digest(); int i; for (byte aB : b) { i = aB; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } String sign = buf.toString(); return sign; } /*** @param obj* @return 拼接后的字符串*/ public static String copy(Object... obj) { StringBuffer mStringBuffer = new StringBuffer(); for (Object anObj : obj) { mStringBuffer.append(anObj); } return mStringBuffer.toString(); } /*** 替換字符串** @param strSc 需要進行替換的字符串* @param oldStr 源字符串* @param newStr 替換后的字符串* @return 替換后對應(yīng)的字符串* @since 1.1*/ public static String replace(String strSc, String oldStr, String newStr) { String ret = strSc; if (ret != null && oldStr != null && newStr != null) { ret = strSc.replaceAll(oldStr, newStr); } return ret; } public static String getSplitString(String srcString, String split) { StringBuilder stringBuilder = new StringBuilder(srcString); for (int i = 4; i < stringBuilder.length(); i += 5) { stringBuilder.insert(i, split); } return stringBuilder.toString(); } public static boolean isContain(String strSc, String str, String splitStr) { String split = ","; if (!isNull(splitStr)) { split = splitStr; } if (!isNull(strSc, str)) { String[] strs = strSc.split(split); for (String newStr : strs) { if (newStr.trim().equals(str)) { return true; } } } return false; } public static String subZeroAndDot(String s) { if (s.indexOf(".") > 0) { s = s.replaceAll("0+?$", "");//去掉多余的0 s = s.replaceAll("[.]$", "");//如最后一位是.則去掉 } return s; } /*** 判斷多個參數(shù)是否都為空** @param strArray* @return*/ public static boolean isNull(Object... strArray) { boolean result = false; for (Object str : strArray) { if (isEmpty(str)) { result = true; break; } else { result = false; } } return result; } /*** 判斷多個參數(shù)是否為空** @param str* @return*/ public static boolean isEmpty(Object str) { return ("").equals(str) || str == null; } /*** 替換字符串,修復(fù)java.lang.String類的replaceAll方法時第一參數(shù)是字符串常量正則時(如:"address".* replaceAll("dd","$");)的拋出異常:java.lang.StringIndexOutOfBoundsException:* String index out of range: 1的問題。** @param strSc 需要進行替換的字符串* @param oldStr 源字符串* @param newStr 替換后的字符串* @return 替換后對應(yīng)的字符串* @since 1.2*/ public static String replaceAll(String strSc, String oldStr, String newStr) { int i = -1; while ((i = strSc.indexOf(oldStr)) != -1) { strSc = new StringBuffer(strSc.substring(0, i)).append(newStr) .append(strSc.substring(i + oldStr.length())).toString(); } return strSc; } /*** 將字符串轉(zhuǎn)換成HTML格式的字符串** @param str 需要進行轉(zhuǎn)換的字符串* @return 轉(zhuǎn)換后的字符串* @since 1.1*/ public static String toHtml(String str) { String html = str; if (str == null || str.length() == 0) { return ""; } else { html = replace(html, "&", "&"); html = replace(html, "<", "<"); html = replace(html, ">", ">"); html = replace(html, "\r\n", "\n"); html = replace(html, "\n", "<br>\n"); html = replace(html, "\"", """); html = replace(html, " ", " "); return html; } } /*** 將HTML格式的字符串轉(zhuǎn)換成常規(guī)顯示的字符串** @param str 需要進行轉(zhuǎn)換的字符串* @return 轉(zhuǎn)換后的字符串* @since 1.1*/ public static String toText(String str) { String text = str; if (str == null || str.length() == 0) { return ""; } else { text = replace(text, "&", "&"); text = replace(text, "<", "<"); text = replace(text, ">", ">"); text = replace(text, "<br>\n", "\n"); text = replace(text, "<br>", "\n"); text = replace(text, """, "\""); text = replace(text, " ", " "); text = replace(text, "“", "“"); text = replace(text, "”", "”"); return text; } } /*** 獲取加密的手機號** @param phoneNum* @return*/ public static String getEncryptMobile(String phoneNum) { if (!checkMobile(phoneNum)) { return phoneNum; } StringBuilder stringBuilder = new StringBuilder(phoneNum.substring(0, 3)); stringBuilder.append("****"); stringBuilder.append(phoneNum.substring(7)); return stringBuilder.toString(); } /*** 檢查手機號** @param phoneNum* @return*/ public static boolean checkMobile(String phoneNum) { Pattern p = Pattern.compile("^1[3|4|5|7|8]\\d{9}$"); Matcher m = p.matcher(phoneNum); return m.matches(); } /*** 驗證固定電話號碼** @param phone 電話號碼,格式:國家(地區(qū))電話代碼 + 區(qū)號(城市代碼) + 電話號碼,如:+8602085588447* <p><b>國家(地區(qū)) 代碼 :</b>標(biāo)識電話號碼的國家(地區(qū))的標(biāo)準(zhǔn)國家(地區(qū))代碼。它包含從 0 到 9 的一位或多位數(shù)字,* 數(shù)字之后是空格分隔的國家(地區(qū))代碼。</p>* <p><b>區(qū)號(城市代碼):</b>這可能包含一個或多個從 0 到 9 的數(shù)字,地區(qū)或城市代碼放在圓括號——* 對不使用地區(qū)或城市代碼的國家(地區(qū)),則省略該組件。</p>* <p><b>電話號碼:</b>這包含從 0 到 9 的一個或多個數(shù)字 </p>* @return 驗證成功返回true,驗證失敗返回false*/ public static boolean checkPhone(String phone) { if (phone.length() != 11 || (!TextUtils.isEmpty(phone) && !phone.startsWith("1"))) { return false; } String regex = "(\\+\\d+)?(\\d{3,4}\\-?)?\\d{7,8}$"; return Pattern.matches(regex, phone); } /*** 檢查密碼有效* 大于6位包含數(shù)字小寫字母和大寫字母** @param pass* @return*/ public static boolean checkPass(String pass) { boolean match = !TextUtils.isEmpty(pass) && pass.length() > 6; //檢查位數(shù) if (match) { String[] patterns = new String[]{"[0-9]+", "[a-zA-Z]+"}; for (String patternStr : patterns) { Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher(pass); matcher.reset().usePattern(pattern); if (!matcher.find()) { match = false; break; } } } return match; } /*** 根據(jù)string.xml資源格式化字符串** @param context* @param resource* @param args* @return*/ public static String formatResourceString(Context context, int resource, Object... args) { String str = context.getResources().getString(resource); if (TextUtils.isEmpty(str)) { return null; } return String.format(str, args); } /*** 驗證身份證號碼** @param idCard 居民身份證號碼15位或18位,最后一位可能是數(shù)字或字母* @return 驗證成功返回true,驗證失敗返回false*/ public static boolean checkIdCard(String idCard) { if (idCard.length() != 15 && idCard.length() != 18) { return false; } String regex = "[1-9]\\d{13,16}[a-zA-Z0-9]{1}"; return Pattern.matches(regex, idCard); } /*** 將元單位數(shù)字轉(zhuǎn)成int類型的元** @param numStr*/ public static int numStrToInt(String numStr) { int num = 0; try { if (!TextUtils.isEmpty(numStr)) { num = Integer.valueOf(numStr); } } catch (Exception e) { e.printStackTrace(); } return num; } /*** 格式化數(shù)字** @param num (int)*/ public static String simpleFormat(int num) { DecimalFormat df = new DecimalFormat("#.#"); StringBuilder numFormat = new StringBuilder(); double numDouble; if (num > 1000 && num < 10000) {//1千以上 numDouble = num / 1000d; numFormat.append(df.format(numDouble)).append("k"); } else if (num > 10000) { // 萬以上 numDouble = num / 10000d; numFormat.append(df.format(numDouble)).append("w"); } else { numFormat.append(num); } return numFormat.toString(); } /*** 數(shù)字轉(zhuǎn)成以萬、億為單位,1.0-->1; 1.1-->1.1** @param numStr (String)*/ public static String newNumFormat(String numStr) { try { long num = Integer.valueOf(numStr); return newNumFormat(num); } catch (Exception e) { e.printStackTrace(); return numStr; } } /*** 數(shù)字轉(zhuǎn)成以萬、億為單位,1.0-->1; 1.1-->1.1** @param num (int)*/ public static String newNumFormat(long num) { DecimalFormat df = new DecimalFormat("#.#"); StringBuilder numFormat = new StringBuilder(); double numDouble; if (num <= 1000000 && num > 10000) { // 萬以上 numDouble = num / 10000d; numFormat.append(df.format(numDouble)).append("萬"); } else if (num > 1000000) { // 百萬以上 numDouble = num / 1000000d; numFormat.append(df.format(numDouble)).append("百萬"); } else { numFormat.append(num); } return numFormat.toString(); } /*** 將一字符串?dāng)?shù)組以某特定的字符串作為分隔來變成字符串** @param strs 字符串?dāng)?shù)組* @param token 分隔字符串* @return 以token為分隔的字符串* @since 1.0*/ public static String join(String[] strs, String token) { if (strs == null) return null; StringBuffer sb = new StringBuffer(); for (int i = 0; i < strs.length; i++) { if (i != 0) sb.append(token); sb.append(strs[i]); } return sb.toString(); } /*** 將一字符串以某特定的字符串作為分隔來變成字符串?dāng)?shù)組** @param str 需要拆分的字符串("@12@34@56")* @param token 分隔字符串("@")* @return 以token為分隔的拆分開的字符串?dāng)?shù)組* @since 1.0*/ public static String[] split(String str, String token) { String temp = str.substring(1, str.length()); return temp.split(token); } /*** 驗證字符串合法性** @param str 需要驗證的字符串* @param test 非法字符串(如:"~!#$%^&*()',;:?")* @return true:非法;false:合法* @since 1.0*/ public static boolean check(String str, String test) { if (str == null || str.equals("")) return true; boolean flag = false; for (int i = 0; i < test.length(); i++) { if (str.indexOf(test.charAt(i)) != -1) { flag = true; break; } } return flag; } /*** 將數(shù)值型字符串轉(zhuǎn)換成Integer型** @param str 需要轉(zhuǎn)換的字符型字符串* @param defaultValue 轉(zhuǎn)換失敗時返回的值* @return 成功則返回轉(zhuǎn)換后的Integer型值;失敗則返回ret* @since 1.0*/ public static Integer String2Integer(String str, Integer defaultValue) { if (TextUtils.isEmpty(str)) { return defaultValue; } try { return Integer.parseInt(str); } catch (NumberFormatException e) { return defaultValue; } } /*** has already set default int value in the method body.** @param str input string to convert to integer value* @return str's int value,if empty return default value*/ public static Integer String2Integer(String str) { return String2Integer(str, DEFAULT_INT); } public static long getLongValue(Object o, long defaultValue) { if (!isNull(o)) { try { return Long.parseLong(String.valueOf(o)); } catch (Exception e) { } } return defaultValue; } /*** 將數(shù)值型轉(zhuǎn)換成字符串** @param it 需要轉(zhuǎn)換的Integer型值* @param ret 轉(zhuǎn)換失敗的返回值* @return 成功則返回轉(zhuǎn)換后的字符串;失敗則返回ret* @since 1.0*/ public static String Integer2String(Integer it, String ret) { try { return Integer.toString(it); } catch (NumberFormatException e) { return ret; } } /*** 比較兩字符串大小(ASCII碼順序)** @param str1 參與比較的字符串1* @param str2 參與比較的字符串2* @return str1>str2:1;str1<str2:-1;str1=str2:0* @since 1.1*/ public static int compare(String str1, String str2) {// if (str1.equals(str2)) { return 0; } int str1Length = str1.length(); int str2Length = str2.length(); int length = 0; if (str1Length > str2Length) { length = str2Length; } else { length = str1Length; } for (int i = 0; i < length; i++) { if (str1.charAt(i) > str2.charAt(i)) { return 1; } } return -1; } /*** 將阿拉伯?dāng)?shù)字的錢數(shù)轉(zhuǎn)換成中文方式** @param num 需要轉(zhuǎn)換的錢的阿拉伯?dāng)?shù)字形式* @return 轉(zhuǎn)換后的中文形式* @since 1.1*/ public static String num2Chinese(double num) { String result = ""; String str = Double.toString(num); if (str.contains(".")) { String begin = str.substring(0, str.indexOf(".")); String end = str.substring(str.indexOf(".") + 1, str.length()); byte[] b = begin.getBytes(); int j = b.length; for (int i = 0, k = j; i < j; i++, k--) { result += getConvert(begin.charAt(i)); if (!"零".equals(result.charAt(result.length() - 1) + "")) { result += getWei(k); } System.out.println(result); } for (int i = 0; i < result.length(); i++) { result = result.replaceAll("零零", "零"); } if ("零".equals(result.charAt(result.length() - 1) + "")) { result = result.substring(0, result.length() - 1); } result += "元"; byte[] bb = end.getBytes(); int jj = bb.length; for (int i = 0, k = jj; i < jj; i++, k--) { result += getConvert(end.charAt(i)); if (bb.length == 1) { result += "角"; } else if (bb.length == 2) { result += getFloat(k); } } } else { byte[] b = str.getBytes(); int j = b.length; for (int i = 0, k = j; i < j; i++, k--) { result += getConvert(str.charAt(i)); result += getWei(k); } } return result; } public static String getString(String str, int count) { if (!(str.charAt(count - 1) >= 'a' && str.charAt(count - 1) <= 'z' || str.charAt(count - 1) >= 'A' && str.charAt(count - 1) <= 'Z')) return str.substring(0, count - 1); else return str.substring(0, count); } private static String getConvert(char num) { if (num == '0') { return "零"; } else if (num == '1') { return "一"; } else if (num == '2') { return "二"; } else if (num == '3') { return "三"; } else if (num == '4') { return "四"; } else if (num == '5') { return "五"; } else if (num == '6') { return "六"; } else if (num == '7') { return "七"; } else if (num == '8') { return "八"; } else if (num == '9') { return "九"; } else { return ""; } } private static String getFloat(int num) { if (num == 2) { return "角"; } else if (num == 1) { return "分"; } else { return ""; } } private static String getWei(int num) { if (num == 1) { return ""; } else if (num == 2) { return "十"; } else if (num == 3) { return "百"; } else if (num == 4) { return "千"; } else if (num == 5) { return "萬"; } else if (num == 6) { return "十"; } else if (num == 7) { return "百"; } else if (num == 8) { return "千"; } else if (num == 9) { return "億"; } else if (num == 10) { return "十"; } else if (num == 11) { return "百"; } else if (num == 12) { return "千"; } else if (num == 13) { return "兆"; } else { return ""; } } /*** 將字符串的首字母改為大寫** @param str 需要改寫的字符串* @return 改寫后的字符串* @since 1.2*/ public static String firstToUpper(String str) { return str.substring(0, 1).toUpperCase() + str.substring(1); } /*** 判斷l(xiāng)ist中是否包含某一個字符串** @param str1* @return*/ public static boolean listContain(List list, String str1) { return !(list == null || list.size() == 0) && list.contains(str1); } /*** list轉(zhuǎn)String** @param list* @param sign 分隔符號* @return*/ public static String List2String(List<String> list, String sign) { if (list == null || list.size() == 0) return null; StringBuffer sb = new StringBuffer(); for (String string : list) { sb.append(string).append(sign); } return sb.substring(0, sb.length() - 1); } /*** String轉(zhuǎn)list 去除null 空串** @param target* @param sign 分隔符號* @return*/ public static List<String> String2List(String target, String sign) { List<String> usersList = new ArrayList<String>(); if (!StringUtil.isEmpty(target)) { String[] vs = target.split(sign); for (String v : vs) { if (!StringUtil.isEmpty(v)) usersList.add(v); } } return usersList; } public static String escapeHtmlSign(String value) { if (value == null) return null; if (value instanceof String) { String result = value; // "'<>& result = result.replaceAll("&", "&").replaceAll(">", ">") .replaceAll("<", "<").replaceAll("\"", """) .replaceAll("'", "'"); return result; } else { return value; } } public static String unEscapeHtmlSign(String value) { if (value == null) return null; if (value instanceof String) { String result = value; // "'<>& result = result.replaceAll("&", "&").replaceAll(">", ">") .replaceAll("<", "<").replaceAll(""", "\"") .replaceAll("'", "'"); return result; } else { return value; } } /*** 根據(jù)Resource ID獲取字符串** @param resId* @return* @deprecated 直接用getString()或者getContext().getString()的系統(tǒng)方法*/ public static String getStringFromId(Application app, int resId) { return app.getString(resId); } /*** 將浮點數(shù)進行四舍五入** @return 改寫后的字符串*/ public static String doubleToString(double str) { return doubleToString(str, 2); } public static String formatNum(float num) { DecimalFormat decimalFormat = new DecimalFormat("0.00"); return decimalFormat.format(num); } public static String numToString(int str) { return doubleToString(str, 2); } public static String doubleToString(double str, int offset) { return new BigDecimal(str + "").setScale(offset, BigDecimal.ROUND_HALF_UP).toString(); } public static Date stringDateTodate(String date) { String time = date.substring(6, date.length() - 7); return new Date(Long.parseLong(time)); } /*** 去除字符串前后的空格** @param text* @return*/ public static String trimString(String text) { if (!TextUtils.isEmpty(text)) { text = text.replaceAll("[ | ]", " ").trim(); //替換全角空格為半角,然后過濾 } return text; } /*** 去除轉(zhuǎn)義** @param text* @return*/ public static String escapeString(String text) { try { if (!TextUtils.isEmpty(text)) { text = text.replaceAll("[\\n\\r]*", ""); } } catch (Exception e) { e.printStackTrace(); } if (TextUtils.isEmpty(text)) text = ""; return text; } /*** 添加url參數(shù)** @param url* @param params* @return*/ public static String appendUrlParams(String url, String params) { if (TextUtils.isEmpty(url)) { return url; } if (url.endsWith("/")) { url = url.substring(0, url.length() - 1); } Pattern pattern = Pattern.compile("\\?[\\w]*="); Matcher matcher = pattern.matcher(url); if (matcher.find()) { return url + "&" + params; } else { return url + "?" + params; } } public static void main(String[] args) { } /*** 設(shè)置一段不同顏色的文字** @param colors:顏色數(shù)組,按順序取,getColor所得的值* @param index:切換顏色對應(yīng)的位置(第幾個內(nèi)容需要變色)* @param s:文字數(shù)組*/ public static SpannableStringBuilder getColorSpan(Integer[] index, int[] colors, CharSequence... s) { List<Integer> indexList = Arrays.asList(index); SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); int colorIndex = 0; for (int i = 0; i < s.length; i++) { if (indexList.contains(Integer.valueOf(i))) { SpannableString spanString = new SpannableString(s[i]); if (colorIndex >= colors.length) { colorIndex = colors.length - 1; } ForegroundColorSpan span = new ForegroundColorSpan(colors[colorIndex]); colorIndex++; spanString.setSpan(span, 0, s[i].length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); stringBuilder.append(spanString); } else { stringBuilder.append(s[i]); } } return stringBuilder; } /*** 字符拆分** @param str 原字符* @param split 分隔符* @return*/ public static String getSubStrSplit(String str, String split) { if (!TextUtils.isEmpty(split) && !TextUtils.isEmpty(str) && str.contains(split)) { str = str.substring(0, str.indexOf(split)); } return str; } /*** 截取指定size的String*/ public static String resizeContent(String content, int size) { StringBuilder resizeContent = new StringBuilder(); if (!TextUtils.isEmpty(content) && content.length() > size) { resizeContent.append(content.substring(0, size)); resizeContent.append("..."); } else { resizeContent.append(content); } return resizeContent.toString(); } /*** 轉(zhuǎn)碼中文字符串** @param srcStr* @return*/ public static String encodeChineseStr(String srcStr) { String dstStr = srcStr; if (!TextUtils.isEmpty(dstStr)) { if (srcStr.length() < srcStr.getBytes().length) { try { dstStr = URLEncoder.encode(dstStr, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } return dstStr; } /*** 用來比較手機號版本** @param s1* @param s2* @return s1<s2*/ public static boolean compareToMin(String s1, String s2) { if (TextUtils.isEmpty(s1) || TextUtils.isEmpty(s2)) { return false; } s1 = s1.replaceAll("[a-zA-Z]", ""); s2 = s2.replaceAll("[a-zA-Z]", ""); int rt = s1.compareTo(s2); if (rt < 0) { return true; } else if (rt > 0) { return false; } else { return false; } } /*** 截取指定長度 從0開始,包左不包右*/ public static String spliteTime(String dateStr, int start, int end) { CharSequence sequence = dateStr.subSequence(start, end); return sequence.toString(); } /*** 是否有中文字符** @param str* @return*/ public static boolean hasChineseChar(String str) { boolean temp = false; Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); Matcher m = p.matcher(str); if (m.find()) { temp = true; } return temp; } /*** 字符是否是中文字符* <p/>* 不包括““”號,“。”號,“,”號* <p/>* GENERAL_PUNCTUATION 判斷中文的“號* <p/>* CJK_SYMBOLS_AND_PUNCTUATION 判斷中文的。號* <p/>* HALFWIDTH_AND_FULLWIDTH_FORMS 判斷中文的,號*/ private static final boolean isChinese(char c) { Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); return ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A; } /*** 判斷字符串是否含有中文字符*/ public static final boolean isContainChinese(String strName) { char[] ch = strName.toCharArray(); for (char c : ch) { if (isChinese(c)) { return true; } } return false; } final static int BUFFER_SIZE = 4096; public static byte[] InputStreamTOByte(InputStream in) { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); try { byte[] data = new byte[BUFFER_SIZE]; int count = -1; while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) outStream.write(data, 0, count); data = null; }catch (Exception e){ e.printStackTrace(); } return outStream.toByteArray(); } }
---------------------
?
作者:月色下的獨輪車
來源:CSDN
原文:https://blog.csdn.net/baidu_31093133/article/details/78911779
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請附上博文鏈接!
總結(jié)
以上是生活随笔為你收集整理的StringUtil 字符串处理工具的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。