English Number to Myanmar Number (Kotlin)

English နံပတ်တွေကို မြန်မာ နံပတ် ပြောင်းတာ swift နဲ့ ရေးကြည့်ပြီးတော့ kotlin အတွက် ပြန်ပြီး ရေးကြည့်ပါတယ်။ Kotlin နဲ့က ပိုရှင်းပြီး လွယ်တယ်။ အထူးသဖြင့် character ကို unicode number ပြောင်းရတာ အရမ်းကို ရှင်းပါတယ်။

fun getMMNumber(eng: String): String {
    try {
        eng.toDouble()
        //it's digit
        var mm = ""
        eng.toCharArray().map { char -> if (char.toInt() >= 48 && char.toInt() <= 57) char.toInt() + 4112 else char.toInt() }.forEach { no -> mm = mm + no.toChar() }
        return mm
    }catch(e: NumberFormatException) {
        return eng
    }
}

Kotlin မှာလည်း extension တွေပါဝင်သည့် အတွက် ကျွန်တော် swift မှာ ရေးသလို Integer , Double စတာတွေ ရဲ့ extension အနေနဲ့ ပြောင်းရေးမယ်ဆိုလည်း ရပါတယ်။

1 Comment

  1. gmail says:

    nice post

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.