How to use NSScanner?

前端 未结 5 1586
走了就别回头了
走了就别回头了 2020-11-27 17:40

I\'ve just read Apple\'s docu of NSScanner. I\'m trying to get the integer of that string: @\"user logged (3 attempts)\".

I can\'t find any example, how to scan with

5条回答
  •  难免孤独
    2020-11-27 18:18

    NSScanner is a linear scanner. You have to scan through the stuff you don't want to get to what you do want.

    You could do [aScanner scanUpToCharactersInSet:[NSCharacterSet decimalDigitCharacterSet] intoString:NULL] to jump past everything up to the number character. Then you do [aScanner scanInteger:&anInteger] to scan the character into an integer.

提交回复
热议问题