2626 */
2727public class StringUtil {
2828 private static final String TAG = "StringUtil" ;
29-
29+
3030 public StringUtil () {
3131 }
3232
@@ -95,24 +95,48 @@ public static String getString(String s) {
9595 return s == null ? "" : s ;
9696 }
9797 /**获取string,为null则返回""
98+ * ignoreEmptyItem = false;
99+ * split = ","
98100 * @param array
99- * @return
101+ * @return {@link #getString(String[], boolean)}
100102 */
101103 public static String getString (String [] array ) {
102- return getString (array , null );
104+ return getString (array , false );
105+ }
106+ /**获取string,为null则返回""
107+ * split = ","
108+ * @param array
109+ * @param ignoreEmptyItem
110+ * @return {@link #getString(String[], String, boolean)}
111+ */
112+ public static String getString (String [] array , boolean ignoreEmptyItem ) {
113+ return getString (array , null , ignoreEmptyItem );
103114 }
104115 /**获取string,为null则返回""
116+ * ignoreEmptyItem = false;
105117 * @param array
106118 * @param split
107- * @return
119+ * @return {@link #getString(String[], String, boolean)}
108120 */
109121 public static String getString (String [] array , String split ) {
122+ return getString (array , split , false );
123+ }
124+ /**获取string,为null则返回""
125+ * @param array
126+ * @param split
127+ * @param ignoreEmptyItem
128+ * @return
129+ */
130+ public static String getString (String [] array , String split , boolean ignoreEmptyItem ) {
110131 String s = "" ;
111132 if (array != null ) {
112133 if (split == null ) {
113134 split = "," ;
114135 }
115136 for (int i = 0 ; i < array .length ; i ++) {
137+ if (ignoreEmptyItem && isEmpty (array [i ], true )) {
138+ continue ;
139+ }
116140 s += ((i > 0 ? split : "" ) + array [i ]);
117141 }
118142 }
@@ -206,8 +230,50 @@ public static int getLength(String s, boolean trim) {
206230 //获取string的长度>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
207231
208232
209- //判断字符是否非空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
233+ //判断字符是否为空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
210234
235+ /**判断字符是否为空
236+ * @param object
237+ * @param trim
238+ * @return
239+ */
240+ public static boolean isEmpty (Object object , boolean trim ) {
241+ return isEmpty (getString (object ), trim );
242+ }
243+ /**判断字符是否为空
244+ * @param cs
245+ * @param trim
246+ * @return
247+ */
248+ public static boolean isEmpty (CharSequence cs , boolean trim ) {
249+ return isEmpty (getString (cs ), trim );
250+ }
251+ /**判断字符是否为空
252+ * @param s
253+ * @param trim
254+ * @return
255+ */
256+ public static boolean isEmpty (String s , boolean trim ) {
257+ // Log.i(TAG, "getTrimedString s = " + s);
258+ if (s == null ) {
259+ return true ;
260+ }
261+ if (trim ) {
262+ s = s .trim ();
263+ }
264+ if (s .isEmpty ()) {
265+ return true ;
266+ }
267+
268+ currentString = s ;
269+
270+ return false ;
271+ }
272+
273+ //判断字符是否为空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
274+
275+ //判断字符是否非空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
276+
211277 /**判断字符是否非空
212278 * @param object
213279 * @param trim
@@ -240,12 +306,12 @@ public static boolean isNotEmpty(String s, boolean trim) {
240306 if (s .length () <= 0 ) {
241307 return false ;
242308 }
243-
309+
244310 currentString = s ;
245-
311+
246312 return true ;
247313 }
248-
314+
249315 //判断字符是否非空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
250316
251317
@@ -261,7 +327,7 @@ public static boolean isNotEmpty(String s, boolean trim) {
261327 namePattern = Pattern .compile ("^[0-9a-zA-Z_]+$" );//已用55个中英字符测试通过
262328 smallAlphaPattern = Pattern .compile ("[a-z]" );
263329 }
264-
330+
265331 //判断手机格式是否正确
266332 public static boolean isPhone (String phone ) {
267333 if (isNotEmpty (phone , true ) == false ) {
@@ -576,7 +642,7 @@ public static String getCorrectEmail(String email) {
576642 public static final int PRICE_FORMAT_PREFIX_WITH_BLANK = 3 ;
577643 public static final int PRICE_FORMAT_SUFFIX_WITH_BLANK = 4 ;
578644 public static final String [] PRICE_FORMATS = {
579- "" , "¥" , "元" , "¥ " , " 元"
645+ "" , "¥" , "元" , "¥ " , " 元"
580646 };
581647
582648 /**获取价格,保留两位小数
0 commit comments