Kotlin fun StrLib
페이지 정보
작성자 sbLAB 댓글 0건 조회 2,590회 작성일 20-07-19 09:08본문
/** md5 */
fun String.md5(): String {
val md = MessageDigest.getInstance("MD5")
return BigInteger(1, md.digest(toByteArray())).toString(16).padStart(32, '0')
}
/** getUUID()
* return -> f890e4a618024485922548a42879995c */
fun getUUID(): String{
var uuid = UUID.randomUUID()
var uuidResult = uuid.toString().replace("-","")
return uuidResult
}
/** 전화번호 체크
* +821077771111 -> 01077771111
*/
fun chk82pn(phoneNumber:String): String{
var pn = phoneNumber.replace("+82", "0")
return pn
}
/**
* EditText maxLength 최대길이 설정
* @param max
*/
fun EditText.maxLength(max: Int){
this.filters = arrayOf<InputFilter>(InputFilter.LengthFilter(max))
}
/**
* 15:25 -> 152500 시분초 형식변환
* hhmm2hhmm00(15:25)
*/
fun hhmm2hhmm00(srcStr:String):String{
return srcStr.replace(":","")+"00"
}
/**
* 6자리Random숫자얻기
* getRandom6digit
*/
fun getRandom6digit():String{
val rand = Random()
return String.format("%06d", rand.nextInt(1000000))
}
/**
* Mysql base64_encode 된 Blob string 을 => 다시 base64_decode 해서 Bitmap 으로 형변경
* StringToBitMap(data.G_IMAGE)
*/
fun StringToBitMap(encodedString: String?): Bitmap? {
return try {
val encodeByte: ByteArray = Base64.decode(encodedString, Base64.DEFAULT)
return BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.size)
} catch (e: Exception) {
e.message
null
}
}
/**
* 숫자만있는지 체크
*
*/
fun numberIsOnlyCheck(text:String):Boolean{
return Pattern.matches("^[0-9]+$",text)
}
댓글목록
등록된 댓글이 없습니다.