字串相關 StringUtils

2021-07-29 16:01:46 字數 2622 閱讀 9592

/***

* author: blankj

* blog :

* time : 2016/8/16

* desc : 字串相關工具類

*

*/public

final

class

stringutils

/*** 判斷字串是否為null或長度為0

** @param s 待校驗字串

* @return : 空

: 不為空

*/public

static

boolean

isempty(charsequence

s) /**

* 判斷字串是否為null或全為空格

** @param s 待校驗字串

* @return : null或全空格

: 不為null且不全空格

*/public

static

boolean

istrimempty(string

s) /**

* 判斷字串是否為null或全為空白字元

** @param s 待校驗字串

* @return : null或全空白字元

: 不為null且不全空白字元

*/public

static

boolean

isspace(string

s) }

return

true;

}/**

* 判斷兩字串是否相等

** @param a 待校驗字串a

* @param b 待校驗字串b

* @return : 相等

: 不相等

*/public

static

boolean

equals(charsequence

a, charsequence

b) else

return

true;}}

return

false;

}/**

* 判斷兩字串忽略大小寫是否相等

** @param a 待校驗字串a

* @param b 待校驗字串b

* @return : 相等

: 不相等

*/public

static

boolean

equalsignorecase(string

a, string

b) /**

* null轉為長度為0的字串

** @param s 待轉字串

* @return s為null轉為長度為0字串,否則不改變

*/public

static

string

null2length0(string

s) /**

* 返回字串長度

** @param s 字串

* @return null返回0,其他返回自身長度

*/public

static

intlength(charsequence

s) /**

* 首字母大寫

** @param s 待轉字串

* @return 首字母大寫字串

*/public

static

string

upperfirstletter(string

s) /**

* 首字母小寫

** @param s 待轉字串

* @return 首字母小寫字串

*/public

static

string

lowerfirstletter(string

s) /**

* 反轉字串

** @param s 待反轉字串

* @return 反轉字串

*/public

static

string

reverse(string

s) return

newstring(chars);

}/**

* 轉化為半形字元

** @param s 待轉字串

* @return 半形字串

*/public

static

string

todbc(string

s) else

if (65281

<= chars[i] && chars[i] <=

65374) else

}return

newstring(chars);

}/**

* 轉化為全形字符

** @param s 待轉字串

* @return 全形字串

*/public

static

string

tosbc(string

s) else

if (33

<= chars[i] && chars[i] <=

126) else

}return

newstring(chars);}}

字串相關

30 字串相關 30.1追加字元 nsmutablestring string nsmutablestring alloc init nsstring stroneintro info stringbyreplacingoccurrencesofstring withstring 30.3字串比較 ...

字串相關

字串轉換相關部落格 使用stringstream字串轉數字 include include includeusing namespace std int main 使用sscanf 進行字串轉數字char str 1234321 int a sscanf str,d a char str 123.3...

字元 字串 相關解釋

空字元 一般來描述乙個字串的結尾,其實是控制符的一種,但不能理解為沒有字元,應該理解為代表什麼都沒有的字元.好比回車0x0a和換行0x0d雖然不顯示,但是也是控制字元的一種.這些字元以前是用於印表機的,所以很多都沒有用了 字串的概念 在c語言中,字串是指由若干個有效字元 其中包括字母 數字 轉義字元...