字串補字元工具類

2021-08-09 05:10:10 字數 1312 閱讀 3613

/**

* 字串右補空格

* @see 該方法預設採用空格(其ascii碼為32)來右補字元

* @see 若想自己指定所補字元,可以使用rightpadforbyte(string str, int size, int padstrbyascii)方法

*/public static string rightpadforbyte(string str, int size)

/*** 字串右補字元

* @see 若str對應的byte長度不小於size,則按照size擷取str對應的byte,而非原樣返回str

* @see 所以size引數很關鍵..事實上之所以這麼處理,是由於支付處理系統介面文件規定了字段的最大長度

* @see 若對普通字串進行右補字元,建議org.apache.commons.lang.stringutils.rightpad(...)

* @param size 該引數指的不是字串長度,而是字串所對應的byte長度

* @param padstrbyascii 該值為所補字元的ascii碼,如32表示空格,48表示0,64表示@等

*/public static string rightpadforbyte(string str, int size, int padstrbyascii)else

return new string(destbyte);

}/**

* 字串左補空格

* @see 該方法預設採用空格(其ascii碼為32)來左補字元

* @see 若想自己指定所補字元,可以使用leftpadforbyte(string str, int size, int padstrbyascii)方法

*/public static string leftpadforbyte(string str, int size)

/*** 字串左補字元

* @see 若str對應的byte長度不小於size,則按照size擷取str對應的byte,而非原樣返回str

* @see 所以size引數很關鍵..事實上之所以這麼處理,是由於支付處理系統介面文件規定了字段的最大長度

* @param padstrbyascii 該值為所補字元的ascii碼,如32表示空格,48表示0,64表示@等

*/public static string leftpadforbyte(string str, int size, int padstrbyascii)else

return new string(destbyte);

}

字串工具類

字串工具類 author administrator public class djystringutils 判斷字串是否不為空 param str 字串 return 是否不為空 public static boolean isnotempty string str 截斷字串兩側的逗號 param...

字串工具類StringUtils

package utils public class stringutils public static string join string array,string str public static string wrapwithsinglequotes string str 把字串內容被逗號...

隨機字串工具類

包名 import org.apache.commons.lang.randomstringutils 或import org.apache.commons.lang.randomstringutils randomstringutils.random int count 產生6位長度的隨機字串,中...