Convert a string into an int

后端 未结 11 2453
别跟我提以往
别跟我提以往 2020-12-04 14:51

I\'m having trouble converting a string into an integer. I googled it but all I can find is how to convert an int into a string. Does anyone know how to do it the other way

相关标签:
11条回答
  • 2020-12-04 15:45

    You can also use like :

    NSInteger getVal = [self.string integerValue];

    0 讨论(0)
  • 2020-12-04 15:49

    Swift 3.0:

    Int("5")
    

    or

    let stringToConvert = "5"
    Int(stringToConvert)
    
    0 讨论(0)
  • 2020-12-04 15:49
    NSString *string = /* Assume this exists. */;
    int value = [string intValue];
    
    0 讨论(0)
  • 2020-12-04 15:51

    Very easy..

    int (name of integer) = [(name of string, no ()) intValue];

    0 讨论(0)
  • 2020-12-04 15:52

    I had to do something like this but wanted to use a getter/setter for mine. In particular I wanted to return a long from a textfield. The other answers all worked well also, I just ended up adapting mine a little as my school project evolved.

    long ms = [self.textfield.text longLongValue];
    return ms;
    
    0 讨论(0)
提交回复
热议问题