Get integer value from string in swift

后端 未结 12 1848
小蘑菇
小蘑菇 2020-11-27 17:14

So I can do this:

var stringNumb: NSString = \"1357\"

var someNumb: CInt = stringNumb.intValue

But I can\'t find the way to do it w/ a

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 17:55

    I'd use:

    var stringNumber = "1234"
    var numberFromString = stringNumber.toInt()
    println(numberFromString)
    

    Note toInt():

    If the string represents an integer that fits into an Int, returns the corresponding integer.

提交回复
热议问题