StringUtils 的一些用法

2021-08-26 21:48:23 字數 1143 閱讀 9692

發現stringutils 的一些方法非常的實用,遂總結之:

commons lang的stringutils包加入到類路徑中。

其中有幾個比較實用的方法:

如果你需要使乙個字串居中(在輸出的時候),可以使用居中方法:

log(stringutils.center("to be centered", 50, "*"));

// ******************to be centered******************

如果你需要重複的書寫同乙個數字,你可以這麼寫:

log(stringutils.leftpad("34", 8, "0"));

// 00000034

log(stringutils.join(new string, ":")

// cat:dog:carrot:leaf:door

如果你需要乙個大寫字母或者是需要乙個字串中的每個單詞第乙個字母大寫,你可以這麼做:

log(stringutils.capitaliseallwords("a sentenced to be capitalised"));

// a sentenced to be capitalised

如果你需要計算乙個字母在字串中出現的個數,你可以使用countmatches方法:log(stringutils.countmatches("bethany plays with army men", "e"));

// 2

我們公司用其中乙個方法生成主鍵:

string seqname = stringutils.trim(stringutils.uppercase("seq_dj"));

string xh = getxh(conn, "dj", null, seqname);

int seqlen = 21 - wslx_dm.length();

xh = wslx_dm + stringutils.leftpad(xh, seqlen, "0");

其中 getxh 裡面有個方法比較實用:

string sql = "select " + seqname + ".nextval as zj_xh from dual";

然後用zj_xh 當做主鍵

oracle 這個nextval  不做過多解釋。

mysql group by,count一些用法

統計 一些資訊以及每個分組的個數 select a.name,a.phone,count as sum from as a group by a.order id 統計 group by 之後的總條數 一共分了多少組 select count as count id from select a.or...

StringUtils中的split的用法

stringutils中的split的用法 stringutils.split string str,string separatorchars 將str按separatorchars分割,str是需要分割的字串,separatorchars是分割字串,分割的方法是按separatorchars的每...

我用的一些mysql函式

只是說明具體引數請檢視其它!mysql get client version 得到客戶版本資訊 mysql get client info 得 到客戶資訊 mysql get host info 主機資訊 mysql get server info 主要功能 得到伺服器資訊 mysql get se...