Android開發_字符串處理類-TextUtils類

 對於字符串處理Android為我們提供瞭一個簡單實用的TextUtils類,如果處理比較簡單的內容不用去思考正則表達式不妨試試這個在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));  

            }  

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *