How do I find out if first character of a string is a number?

前端 未结 6 1175
暖寄归人
暖寄归人 2020-11-29 18:13

In Java is there a way to find out if first character of a string is a number?

One way is

string.startsWith(\"1\")

and do the abov

6条回答
  •  甜味超标
    2020-11-29 19:08

    IN KOTLIN :

    Suppose that you have a String like this :

    private val phoneNumber="9121111111"
    

    At first you should get the first one :

    val firstChar=phoneNumber.slice(0..0)
    

    At second you can check the first char that return a Boolean :

    firstChar.isInt() // or isFloat()
    

提交回复
热议问题