Kotlin/Util

· Kotlin/Util
Kotlin 소수 판별 함수 private fun isPrime(n: Int): Boolean { if (n == 0 || n == 1) return false var i = 2 while (i * i
· Kotlin/Util
개인정보나 암호와 같은 민감한 Text들을 * 처리 이메일 끝 3자리 *** 표시 ex) abc@email.com -> ***@email.com fun getEmailMasking(email: String): String { val result = StringBuffer() val REGEX_EMAIL = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$" val pattern = Pattern.compile(REGEX_EMAIL, Pattern.CASE_INSENSITIVE) if (!pattern.matcher(email).matches()) { //이메일 형식이 맞지 않았을 때 r..
· Kotlin/Util
특정 주소에 네트워크 연결상태를 확인하기 위해서 ping을 사용한다. Kotlin val networkThread = Thread { try { val runTime = Runtime.getRuntime() val cmd = "ping -c 1 -W 2 $ip" //ip는 test 하고 싶은 주소 String 을 넣어주면 된다. val proc = runTime.exec(cmd) proc.waitFor() //여기서 반환되는 ping 테스트의 결과 값은 0, 1, 2 중 하나이다. // 0 : 성공, 1 : fail, 2 : error val result = proc.exitValue() when (result) { 0 -> Log.d("FragmentSelfCheck", ip.toString() + "..
· Kotlin/Util
개발을 할 때 지정해준 시간 이후 지정하는 동작을 수행하는 Util이 필요한데 따로 저장해두면 편할 거 같아 블로그에 남긴다. abstract class TimerUtil { private var mDelayTime = 1000L // default ms private var mName = "none" var isStart = false companion object { private const val WHAT = 100 } constructor(){} constructor(name: String) { mName = name } constructor(name: String, milisecond: Long) { mName = name mDelayTime = milisecond } abstract fun o..
· Kotlin/Util
가격 자리 수마다 , (콤마)를 표현할 때 사용하는 함수 fun getDecimalFormatPrice(price: String?): String? { // String용 var result = "0" if (price == null || price.isEmpty()) return result val dfs = DecimalFormatSymbols() dfs.groupingSeparator = ',' val df = DecimalFormat("#,##0") //#대신 0을 주면 무조건 0으로 대체 df.groupingSize = 3 //3자리수 마다 그룹핑 df.decimalFormatSymbols = dfs val dPrice = price.toDouble() result = df.format(dPri..
bumjae
'Kotlin/Util' 카테고리의 글 목록