1. 

fun String.westernArabicNumeralsOnly():String
{
    val sb = StringBuffer()
    for ( c in this)
    {
        if (c in '0'..'9')
        {
            sb.append(c)
        }
    }
    return sb.toString()
}

 

2. 

fun String.getNumbers():Int
{
return this.filter { it in '0'..'9' }.toInt()
}

 

 

filter 처리 해서 사용 하는것이 더 간단하게 사용 할 수 있음..

'Development > Kotlin' 카테고리의 다른 글

Kotlin Sha256  (0) 2019.10.16
When Intelli is not working.  (0) 2019.07.04
Kotlin run,with,let,apply  (0) 2018.04.09
Kotlin Study Link  (0) 2018.04.03

+ Recent posts