對於字串處理Android為我們提供了一個簡單實用的TextUtils類,如果處理比較簡單的內容不用去思考Regex不妨試試這個在android.text.TextUtils的類,主要的功能如下: 是否為空白字元 static boolean isEmpty(CharSequence str) 拆分字串 public static String[] split (String text, String expression) ,Android開發網提示大家仔細看例子如下 String.split() returns [''] when the string to be split is empty. This returns []. This does not remove any empty strings from the result. For example split("a,", "," ) returns {"a", ""}. 拆分字串使用正則 public static String[] split (String text, Pattern pattern) 確定大小寫是否有效在當前位置的文本TextUtils.getCapsMode(CharSequence cs, int off, int reqModes) 使用HTML編碼這個字串 static String TextUtils.htmlEncode(String s)
<span style="color:#ff0000;">if (!TextUtils.isEmpty(spUtil.getUserId())) {</span> Intent intent = new Intent(WelcomeActivity.this, MainActivity.class); startActivity(intent); } else { startActivity(new Intent(WelcomeActivity.this,
FirstSetActivity.class)); }