/*Copyright (C) 2026 the APIJSON group. All rights reserved. This source code is licensed under the Apache License Version 2.0.*/ package apijson; import java.io.File; import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.Objects; import java.util.regex.Pattern; /**éç¨å符串(String)ç¸å ³ç±»,为nullæ¶è¿å"" * @author Lemon * @use StringUtil. */ public class StringUtil { private static final String TAG = "StringUtil"; public StringUtil() { } public static final String UTF_8 = "utf-8"; public static final String EMPTY = "æ "; public static final String UNKNOWN = "æªç¥"; public static final String UNLIMITED = "ä¸é"; public static final String I = "æ"; public static final String YOU = "ä½ "; public static final String HE = "ä»"; public static final String SHE = "她"; public static final String IT = "å®"; public static final String MALE = "ç·"; public static final String FEMALE = "女"; public static final String TODO = "æªå®æ"; public static final String DONE = "已宿"; public static final String FAIL = "失败"; public static final String SUCCESS = "æå"; public static final String SUNDAY = "æ¥"; public static final String MONDAY = "ä¸"; public static final String TUESDAY = "äº"; public static final String WEDNESDAY = "ä¸"; public static final String THURSDAY = "å"; public static final String FRIDAY = "äº"; public static final String SATURDAY = "å "; public static final String YUAN = "å "; private static String current = ""; /**è·ååä¼ å ¥å¤çåç string * @must ä¸ä¸ªå½±å current çæ¹æ³ å è¿ä¸ªæ¹æ³é½åºè¯¥å¨åä¸çº¿ç¨ä¸ï¼å¦åè¿åå¼å¯è½ä¸å¯¹ * @return */ public static String cur() { return get(current); } /**FIXME æ¹ç¨ cur * @must ä¸ä¸ªå½±åcurrentStringçæ¹æ³ å è¿ä¸ªæ¹æ³é½åºè¯¥å¨åä¸çº¿ç¨ä¸ï¼å¦åè¿åå¼å¯è½ä¸å¯¹ * @return */ @Deprecated public static String getCurrentString() { return cur(); } //è·åstring,为nullæ¶è¿å"" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /**è·åstring,为nullåè¿å"" * @param obj * @return */ public static String get(Object obj) { return obj == null ? "" : obj.toString(); } /**è·åstring,为nullåè¿å"" * @param s * @return */ public static String get(String s) { return s == null ? "" : s; } /**è·åstring,为nullåè¿å"" * ignoreEmptyItem = false; * split = "," * @param arr * @return {@link #get(Object[], boolean)} */ public static String get(Object[] arr) { return get(arr, false); } /**è·åstring,为nullåè¿å"" * split = "," * @param arr * @param ignoreEmptyItem * @return {@link #get(Object[], boolean)} */ public static String get(Object[] arr, boolean ignoreEmptyItem) { return get(arr, null, ignoreEmptyItem); } /**è·åstring,为nullåè¿å"" * ignoreEmptyItem = false; * @param arr * @param split * @return {@link #get(Object[], String, boolean)} */ public static String get(Object[] arr, String split) { return get(arr, split, false); } //CS304 Issue link: https://github.com/APIJSON/APIJSON/issues/182 /**è·åstring,为nullåè¿å"" * @param arr -the str arr given * @param split -the token used to split * @param ignoreEmptyItem -whether to ignore empty item or not * @return {@link #get(Object[], String, boolean)} *
Here we replace the simple "+" way of concatenating with Stringbuilder 's append
*/ public static String get(Object[] arr, String split, boolean ignoreEmptyItem) { StringBuilder s = new StringBuilder(""); if (arr != null) { if (split == null) { split = ","; } for (int i = 0; i < arr.length; i++) { if (ignoreEmptyItem && isEmpty(arr[i], true)) { continue; } s.append(((i > 0 ? split : "") + arr[i])); } } return get(s.toString()); } /**FIXME ç¨ get æ¿ä»£ * @param object * @return */ @Deprecated public static String getString(Object object) { return object == null ? "" : object.toString(); } /**FIXME ç¨ get æ¿ä»£ * @param cs * @return */ @Deprecated public static String getString(CharSequence cs) { return cs == null ? "" : cs.toString(); } /**FIXME ç¨ get æ¿ä»£ * @param s * @return */ @Deprecated public static String getString(String s) { return s == null ? "" : s; } /**FIXME ç¨ get æ¿ä»£ * ignoreEmptyItem = false; * split = "," * @param array * @return {@link #get(Object[], boolean)} */ @Deprecated public static String getString(Object[] array) { return get(array, false); } /**FIXME ç¨ get æ¿ä»£ * split = "," * @param array * @param ignoreEmptyItem * @return {@link #get(Object[], boolean)} */ @Deprecated public static String getString(Object[] array, boolean ignoreEmptyItem) { return get(array, null, ignoreEmptyItem); } /**FIXME ç¨ get æ¿ä»£ * ignoreEmptyItem = false; * @param array * @param split * @return {@link #get(Object[], String, boolean)} */ @Deprecated public static String getString(Object[] array, String split) { return get(array, split, false); } //CS304 Issue link: https://github.com/APIJSON/APIJSON/issues/182 /**FIXME ç¨ get æ¿ä»£ * @param array -the str array given * @param split -the token used to split * @param ignoreEmptyItem -whether to ignore empty item or not * @return {@link #get(Object[], String, boolean)} *Here we replace the simple "+" way of concatenating with Stringbuilder 's append
*/ @Deprecated public static String getString(Object[] array, String split, boolean ignoreEmptyItem) { return get(array, split, ignoreEmptyItem); } //è·åstring,为nullæ¶è¿å"" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //è·å廿ååç©ºæ ¼åçstring<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /**è·å廿ååç©ºæ ¼åçstring,为nullåè¿å"" * @param obj * @return */ public static String trim(Object obj) { return trim(get(obj)); } /**è·å廿ååç©ºæ ¼åçstring,为nullåè¿å"" * @param cs * @return */ public static String trim(CharSequence cs) { return trim(get(cs)); } /**è·å廿ååç©ºæ ¼åçstring,为nullåè¿å"" * @param s * @return */ public static String trim(String s) { return get(s).trim(); } /**FIXME ç¨ trim æ¿ä»£ * @param object * @return */ @Deprecated public static String getTrimedString(Object object) { return trim(object); } /**FIXME ç¨ trim æ¿ä»£ * @param cs * @return */ @Deprecated public static String getTrimedString(CharSequence cs) { return trim(cs); } /**FIXME ç¨ trim æ¿ä»£ * @param s * @return */ @Deprecated public static String getTrimedString(String s) { return trim(s); } //è·å廿ååç©ºæ ¼åçstring>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //è·å廿ææç©ºæ ¼åçstring <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /**è·å廿ææç©ºæ ¼åçstring,为nullåè¿å"" * @param obj * @return */ public static String noBlank(Object obj) { return noBlank(get(obj)); } /**è·å廿ææç©ºæ ¼åçstring,为nullåè¿å"" * @param cs * @return */ public static String noBlank(CharSequence cs) { return noBlank(get(cs)); } /**è·å廿ææç©ºæ ¼åçstring,为nullåè¿å"" * @param s * @return */ public static String noBlank(String s) { return get(s).replaceAll("\\s", ""); } /**FIXME ç¨ noBlank æ¿ä»£ * @param object * @return */ @Deprecated public static String getNoBlankString(Object object) { return noBlank(object); } /**FIXME ç¨ noBlank æ¿ä»£ * @param cs * @return */ @Deprecated public static String getNoBlankString(CharSequence cs) { return noBlank(cs); } /**FIXME ç¨ noBlank æ¿ä»£ * @param s * @return */ @Deprecated public static String getNoBlankString(String s) { return noBlank(s); } //è·å廿ææç©ºæ ¼åçstring >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //è·åstringçé¿åº¦<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /**è·åstringçé¿åº¦,为nullåè¿å0 * @param object * @param trim * @return */ public static int length(Object object, boolean trim) { return length(get(object), trim); } /**è·åstringçé¿åº¦,为nullåè¿å0 * @param cs * @param trim * @return */ public static int length(CharSequence cs, boolean trim) { return length(get(cs), trim); } /**è·åstringçé¿åº¦,为nullåè¿å0 * @param s * @param trim * @return */ public static int length(String s, boolean trim) { s = trim ? trim(s) : s; return get(s).length(); } /**FIXME ç¨ length æ¿ä»£ * @param object * @param trim * @return */ @Deprecated public static int getLength(Object object, boolean trim) { return length(object, trim); } /**FIXME ç¨ length æ¿ä»£ * @param cs * @param trim * @return */ @Deprecated public static int getLength(CharSequence cs, boolean trim) { return length(cs, trim); } /**FIXME ç¨ length æ¿ä»£ * @param s * @param trim * @return */ @Deprecated public static int getLength(String s, boolean trim) { return length(s, trim); } //è·åstringçé¿åº¦>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //夿å符æ¯å¦ä¸ºç©º <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /**夿å符æ¯å¦ä¸ºç©º trim = true * @param obj * @return */ public static boolean isEmpty(Object obj) { return isEmpty(obj, true); } /**夿å符æ¯å¦ä¸ºç©º * @param obj * @param trim * @return */ public static boolean isEmpty(Object obj, boolean trim) { return isEmpty(get(obj), trim); } /**夿å符æ¯å¦ä¸ºç©º trim = true * @param cs * @return */ public static boolean isEmpty(CharSequence cs) { return isEmpty(cs, true); } /**夿å符æ¯å¦ä¸ºç©º * @param cs * @param trim * @return */ public static boolean isEmpty(CharSequence cs, boolean trim) { return isEmpty(get(cs), trim); } /**夿å符æ¯å¦ä¸ºç©º trim = true * @param s * @return */ public static boolean isEmpty(String s) { return isEmpty(s, true); } /**夿å符æ¯å¦ä¸ºç©º * @param s * @param trim * @return */ public static boolean isEmpty(String s, boolean trim) { // Log.i(TAG, "isEmpty s = " + s); if (s == null) { return true; } if (trim) { s = s.trim(); } if (s.isEmpty()) { return true; } current = s; return false; } //夿å符æ¯å¦ä¸ºç©º >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //夿å符æ¯å¦é空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /**夿å符æ¯å¦é空 trim = true * @param obj * @return */ public static boolean isNotEmpty(Object obj) { return ! isEmpty(obj); } /**夿å符æ¯å¦é空 * @param obj * @param trim * @return */ public static boolean isNotEmpty(Object obj, boolean trim) { return ! isEmpty(obj, trim); } /**夿å符æ¯å¦é空 trim = true * @param cs * @return */ public static boolean isNotEmpty(CharSequence cs) { return ! isEmpty(cs); } /**夿å符æ¯å¦é空 * @param cs * @param trim * @return */ public static boolean isNotEmpty(CharSequence cs, boolean trim) { return ! isEmpty(cs, trim); } /**夿å符æ¯å¦é空 trim = true * @param s * @return */ public static boolean isNotEmpty(String s) { return ! isEmpty(s); } /**夿å符æ¯å¦é空 * @param s * @param trim * @return */ public static boolean isNotEmpty(String s, boolean trim) { return ! isEmpty(s, trim); } //夿å符æ¯å¦é空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //夿å符类å <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< public static final Pattern PATTERN_NUMBER; public static final Pattern PATTERN_PHONE; public static final Pattern PATTERN_EMAIL; public static final Pattern PATTERN_ID_CARD; public static final Pattern PATTERN_NUM_OR_ALPHA; public static final Pattern PATTERN_ALPHA; public static final Pattern PATTERN_PASSWORD; //TODO public static final Pattern PATTERN_NAME; public static final Pattern PATTERN_ALPHA_BIG; public static final Pattern PATTERN_ALPHA_SMALL; public static final Pattern PATTERN_BRANCH_URL; static { PATTERN_NUMBER = Pattern.compile("^[0-9]+$"); PATTERN_NUM_OR_ALPHA = Pattern.compile("^[0-9a-zA-Z_.:]+$"); PATTERN_ALPHA = Pattern.compile("^[a-zA-Z]+$"); PATTERN_ALPHA_BIG = Pattern.compile("^[A-Z]+$"); PATTERN_ALPHA_SMALL = Pattern.compile("^[a-z]+$"); PATTERN_NAME = Pattern.compile("^[0-9a-zA-Z_.:]+$");//å·²ç¨55个ä¸è±å符æµè¯éè¿ //newest phone regex expression reference https://github.com/VincentSit/ChinaMobilePhoneNumberRegex PATTERN_PHONE = Pattern.compile("^1(?:3\\d{3}|5[^4\\D]\\d{2}|8\\d{3}|7(?:[0-35-9]\\d{2}|4(?:0\\d|1[0-2]|9\\d))|9[0-35-9]\\d{2}|6[2567]\\d{2}|4(?:(?:10|4[01])\\d{3}|[68]\\d{4}|[579]\\d{2}))\\d{6}$"); PATTERN_EMAIL = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"); PATTERN_ID_CARD = Pattern.compile("(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}$)"); PATTERN_PASSWORD = Pattern.compile("^[0-9a-zA-Z]+$"); PATTERN_BRANCH_URL = Pattern.compile("^[0-9a-zA-Z-_/]+$"); } /**å¤æææºæ ¼å¼æ¯å¦æ£ç¡® * @param phone * @return */ public static boolean isPhone(String phone) { if (isNotEmpty(phone, true) == false) { return false; } current = phone; return PATTERN_PHONE.matcher(phone).matches(); } /**å¤æææºæ ¼å¼æ¯å¦æ£ç¡® * @param s * @return */ public static boolean isPassword(String s) { return length(s, false) >= 6 && PATTERN_PASSWORD.matcher(s).matches(); } /**夿æ¯å¦å ¨æ¯æ°åå¯ç * @param s * @return */ public static boolean isNumberPassword(String s) { return length(s, false) == 6 && isNumber(s); } /**夿emailæ ¼å¼æ¯å¦æ£ç¡® * @param email * @return */ public static boolean isEmail(String email) { if (isEmpty(email, true)) { return false; } current = email; return PATTERN_EMAIL.matcher(email).matches(); } /**夿æ¯å¦å ¨æ¯éªè¯ç * @param s * @return */ public static boolean isVerify(String s) { return length(s, false) >= 4 && isNumber(s); } /**夿æ¯å¦å ¨æ¯æ°å * @param s * @return */ public static boolean isNumber(String s) { if (isEmpty(s, true)) { return false; } current = s; return PATTERN_NUMBER.matcher(s).matches(); } /**夿æ¯å¦å ¨æ¯åæ¯ * @param s * @return */ public static boolean isAlpha(String s) { if (isEmpty(s, true)) { return false; } current = s; return PATTERN_ALPHA.matcher(s).matches(); } /**夿æ¯å¦å ¨æ¯æ°åæåæ¯ * @param s * @return */ public static boolean isNumberOrAlpha(String s) { return isNumber(s) || isAlpha(s); } /**夿æ¯å¦å ¨æ¯æ°åæåæ¯ * @param s * @return */ public static boolean isCombineOfNumOrAlpha(String s) { if (isEmpty(s, true)) { return false; } current = s; return PATTERN_NUM_OR_ALPHA.matcher(s).matches(); } /**夿æ¯å¦ä¸ºä»£ç åç§°ï¼åªè½å å«åæ¯ï¼æ°åæä¸å线 * @param s * @return */ public static boolean isName(String s) { if (s == null || s.isEmpty()) { return false; } String first = s.substring(0, 1); if ("_".equals(first) == false && PATTERN_ALPHA.matcher(first).matches() == false) { return false; } return s.length() <= 1 ? true : PATTERN_NAME.matcher(s.substring(1)).matches(); } /**夿æ¯å¦ä¸ºé¦åæ¯å¤§åç代ç åç§° * @param s * @return */ public static boolean isBigName(String s) { if (s == null || s.isEmpty() || PATTERN_ALPHA_BIG.matcher(s.substring(0, 1)).matches() == false) { return false; } return s.length() <= 1 ? true : PATTERN_NAME.matcher(s.substring(1)).matches(); } /**夿æ¯å¦ä¸ºé¦åæ¯å°åç代ç åç§° * @param s * @return */ public static boolean isSmallName(String s) { if (s == null || s.isEmpty() || PATTERN_ALPHA_SMALL.matcher(s.substring(0, 1)).matches() == false) { return false; } return s.length() <= 1 ? true : PATTERN_NAME.matcher(s.substring(1)).matches(); } /**夿åç¬¦ç±»åæ¯å¦æ¯èº«ä»½è¯å· * @param number * @return */ public static boolean isIDCard(String number) { if (isCombineOfNumOrAlpha(number) == false) { return false; } number = get(number); if (number.length() == 15) { Log.i(TAG, "isIDCard number.length() == 15 old IDCard"); current = number; return true; } if (number.length() == 18) { current = number; return true; } return false; } public static final String HTTP = "http"; public static final String URL_PREFIX = "http://"; public static final String URL_PREFIXs = "https://"; /**夿åç¬¦ç±»åæ¯å¦æ¯ç½å * @param url * @return */ public static boolean isUrl(String url) { if (isNotEmpty(url, true) == false) { return false; } if (! url.startsWith(URL_PREFIX) && ! url.startsWith(URL_PREFIXs)) { return false; } current = url; return true; } public static boolean isBranchUrl(String branchUrl) { if (isEmpty(branchUrl, false)) { return false; } return PATTERN_BRANCH_URL.matcher(branchUrl).matches(); } public static final String FILE_PATH_PREFIX = "file://"; /**夿æä»¶è·¯å¾æ¯å¦åå¨ * @param path * @return */ public static boolean isFilePathExist(String path) { return StringUtil.isFilePath(path) && new File(path).exists(); } public static final String SEPARATOR = "/"; /**夿æ¯å¦ä¸ºè·¯å¾ * @param path * @return */ public static boolean isPath(String path) { return StringUtil.isNotEmpty(path, true) && path.contains(SEPARATOR) && path.contains(SEPARATOR + SEPARATOR) == false && path.endsWith(SEPARATOR) == false; } /**夿åç¬¦ç±»åæ¯å¦æ¯è·¯å¾ * @param path * @return */ public static boolean isFilePath(String path) { if (isNotEmpty(path, true) == false) { return false; } if (! path.contains(".") || path.endsWith(".")) { return false; } current = path; return true; } //夿å符类å >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //æåç¹æ®å符<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /**廿stringå ææéæ°åç±»åå符 * @param object * @return */ public static String getNumber(Object object) { return getNumber(get(object)); } /**廿stringå ææéæ°åç±»åå符 * @param cs * @return */ public static String getNumber(CharSequence cs) { return getNumber(get(cs)); } /**廿stringå ææéæ°åç±»åå符 * @param s * @return */ public static String getNumber(String s) { return getNumber(s, false); } //CS304 Issue link: https://github.com/APIJSON/APIJSON/issues/182 /**廿stringå ææéæ°åç±»åå符 * @param s -string passed in * @param onlyStart ä¸é´æéæ°åæ¶åªè·ååé¢çæ°å * @return limit String *Here we replace the simple "+" way of concatenating with Stringbuilder 's append
*/ public static String getNumber(String s, boolean onlyStart) { if (isEmpty(s, true)) { return ""; } StringBuilder numberString = new StringBuilder(""); String single; for (int i = 0; i < s.length(); i++) { single = s.substring(i, i + 1); if (isNumber(single)) { numberString.append(single); } else { if (onlyStart) { return numberString.toString(); } } } return numberString.toString(); } //æåç¹æ®å符>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //æ ¡æ£ï¼èªå¨è¡¥å ¨çï¼å符串<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /**è·åç½åï¼èªå¨è¡¥å ¨ * @param url * @return */ public static String getCorrectUrl(String url) { Log.i(TAG, "getCorrectUrl : \n" + url); if (isNotEmpty(url, true) == false) { return ""; } // if (! url.endsWith("/") && ! url.endsWith(".html")) { // url = url + "/"; // } if (isUrl(url) == false) { return URL_PREFIX + url; } return url; } /**è·åå»æææ ç©ºæ ¼ ã"-" ã"+86" åçphone * @param phone * @return */ public static String getCorrectPhone(String phone) { if (isNotEmpty(phone, true) == false) { return ""; } phone = noBlank(phone); phone = phone.replaceAll("-", ""); if (phone.startsWith("+86")) { phone = phone.substring(3); } return phone; } /**è·åé®ç®±ï¼èªå¨è¡¥å ¨ * @param email * @return */ public static String getCorrectEmail(String email) { if (isNotEmpty(email, true) == false) { return ""; } email = noBlank(email); if (isEmail(email) == false && ! email.endsWith(".com")) { email += ".com"; } return email; } public static final int PRICE_FORMAT_DEFAULT = 0; public static final int PRICE_FORMAT_PREFIX = 1; public static final int PRICE_FORMAT_SUFFIX = 2; public static final int PRICE_FORMAT_PREFIX_WITH_BLANK = 3; public static final int PRICE_FORMAT_SUFFIX_WITH_BLANK = 4; public static final String[] PRICE_FORMATS = { "", "ï¿¥", "å ", "ï¿¥ ", " å " }; /**è·åä»·æ ¼ï¼ä¿ç两ä½å°æ° * @param price * @return */ public static String getPrice(String price) { return getPrice(price, PRICE_FORMAT_DEFAULT); } //CS304 Issue link: https://github.com/APIJSON/APIJSON/issues/182 /**è·åä»·æ ¼ï¼ä¿ç两ä½å°æ° * @param price -price passed in * @param formatType æ·»å åä½ï¼å ï¼ * @return limit String *Here we replace the simple "+" way of concatenating with Stringbuilder 's append
*/ public static String getPrice(String price, int formatType) { if (isNotEmpty(price, true) == false) { return getPrice(0, formatType); } //åç¬åå°getCorrectPrice? <<<<<<<<<<<<<<<<<<<<<< String correctPrice; StringBuilder correctPriceBuilder = new StringBuilder(""); String s; for (int i = 0; i < price.length(); i++) { s = price.substring(i, i + 1); if (".".equals(s) || isNumber(s)) { correctPriceBuilder.append(s); } } correctPrice = correctPriceBuilder.toString(); //åç¬åå°getCorrectPrice? >>>>>>>>>>>>>>>>>>>>>> Log.i(TAG, "getPrice <<<<<<<<<<<<<<<<<< correctPrice = " + correctPrice); if (correctPrice.contains(".")) { // if (correctPrice.startsWith(".")) { // correctPrice = 0 + correctPrice; // } if (correctPrice.endsWith(".")) { correctPrice = correctPrice.replaceAll(".", ""); } } Log.i(TAG, "getPrice correctPrice = " + correctPrice + " >>>>>>>>>>>>>>>>"); return isNotEmpty(correctPrice, true) ? getPrice(new BigDecimal(0 + correctPrice), formatType) : getPrice(0, formatType); } /**è·åä»·æ ¼ï¼ä¿ç两ä½å°æ° * @param price * @return */ public static String getPrice(BigDecimal price) { return getPrice(price, PRICE_FORMAT_DEFAULT); } /**è·åä»·æ ¼ï¼ä¿ç两ä½å°æ° * @param price * @return */ public static String getPrice(double price) { return getPrice(price, PRICE_FORMAT_DEFAULT); } /**è·åä»·æ ¼ï¼ä¿ç两ä½å°æ° * @param price * @param formatType æ·»å åä½ï¼å ï¼ * @return */ public static String getPrice(BigDecimal price, int formatType) { return getPrice(price == null ? 0 : price.doubleValue(), formatType); } /**è·åä»·æ ¼ï¼ä¿ç两ä½å°æ° * @param price * @param formatType æ·»å åä½ï¼å ï¼ * @return */ public static String getPrice(double price, int formatType) { String s = new DecimalFormat("#########0.00").format(price); switch (formatType) { case PRICE_FORMAT_PREFIX: return PRICE_FORMATS[PRICE_FORMAT_PREFIX] + s; case PRICE_FORMAT_SUFFIX: return s + PRICE_FORMATS[PRICE_FORMAT_SUFFIX]; case PRICE_FORMAT_PREFIX_WITH_BLANK: return PRICE_FORMATS[PRICE_FORMAT_PREFIX_WITH_BLANK] + s; case PRICE_FORMAT_SUFFIX_WITH_BLANK: return s + PRICE_FORMATS[PRICE_FORMAT_SUFFIX_WITH_BLANK]; default: return s; } } public static String join(String[] arr) { return join(arr); } /** æ°ç»ä»¥æå®åésæ¼æ¥ * @param arr * @param s * @return */ public static String join(String[] arr, String s) { if (s == null) { s = ","; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < arr.length; i++) { sb.append(arr[i]); if (i < arr.length-1) { sb.append(s); } } return sb.toString(); } /**åå²è·¯å¾ * @param path * @return */ public static String[] splitPath(String path) { if (StringUtil.isNotEmpty(path, true) == false) { return null; } return isPath(path) ? split(path, SEPARATOR) : new String[] {path}; } /**å°så岿String[] * @param s * @return */ public static String[] split(String s) { return split(s, null); } /**å°sç¨splitå岿String[] * trim = true; * @param s * @param split * @return */ public static String[] split(String s, String split) { return split(s, split, true); } /**å°sç¨splitå岿String[] * @param s * @param trim 廿åå两端çsplit * @return */ public static String[] split(String s, boolean trim) { return split(s, null, trim); } /**å°sç¨splitå岿String[] * @param s * @param split * @param trim 廿åå两端çsplit * @return */ public static String[] split(String s, String split, boolean trim) { s = get(s); if (s.isEmpty()) { return null; } if (isEmpty(split, false)) { split = ","; } if (trim) { while (s.startsWith(split)) { s = s.substring(split.length()); } while (s.endsWith(split)) { s = s.substring(0, s.length() - split.length()); } } return s.contains(split) ? s.split(split) : new String[]{s}; } /** * @param key * @param suffix * @return key + suffixï¼ç¬¬ä¸ä¸ªåæ¯å°å */ public static String addSuffix(String key, String suffix) { key = noBlank(key); if (key.isEmpty()) { return firstCase(suffix); } return firstCase(key) + firstCase(suffix, true); } /** * @param key */ public static String firstCase(String key) { return firstCase(key, false); } /** * @param key * @param upper * @return */ public static String firstCase(String key, boolean upper) { key = get(key); if (key.isEmpty()) { return ""; } String first = key.substring(0, 1); key = (upper ? first.toUpperCase() : first.toLowerCase()) + key.substring(1, key.length()); return key; } /**å ¨é¨å¤§å * @param s * @return */ public static String toUpperCase(String s) { return toUpperCase(s, false); } /**å ¨é¨å¤§å * @param s * @param trim * @return */ public static String toUpperCase(String s, boolean trim) { s = trim ? trim(s) : get(s); return s.toUpperCase(); } /**å ¨é¨å°å * @param s * @return */ public static String toLowerCase(String s) { return toLowerCase(s, false); } /**å ¨é¨å°å * @param s * @return */ public static String toLowerCase(String s, boolean trim) { s = trim ? trim(s) : get(s); return s.toLowerCase(); } public static String concat(String left, String right) { return concat(left, right, null); } public static String concat(String left, String right, String split) { return concat(left, right, split, true); } public static String concat(String left, String right, boolean trim) { return concat(left, right, null, trim); } public static String concat(String left, String right, String split, boolean trim) { if (isEmpty(left, trim)) { return right; } if (isEmpty(right, trim)) { return left; } if (split == null) { split = ","; } return left + split + right; } //æ ¡æ£ï¼èªå¨è¡¥å ¨çï¼å符串>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> public static boolean equals(Object s1, Object s2) { return Objects.equals(s1, s2); } public static boolean equalsIgnoreCase(String s1, String s2) { if (s1 == s2) { return true; } if (s1 == null || s2 == null) { return false; } return s1.equalsIgnoreCase(s2); } }