<span style= "FONT-SIZE:18PX;" > NSString *bananas = @ "123.321abc137d EFG hij KL"; NSString *separatorstring = @ "FG"; BOOL result; Nsscanner *ascanner = [Nsscanner Scannerwithstring:bananas]; Scan the string//to stop when scanning to the specified string, returning the string NSLog (@ "Scanner location:%lu", ascanner.scanlocation) with the result of the specified string; NSString *container; result = [Ascanner scanuptostring:separatorstring intostring:&container]; NSLog (@ "Scan succeeded:%@", [email protected] "yes": @ "NO"); NSLog (@ "Scan returned results:%@", container); NSLog (@ "Scanner location:%lu", ascanner.scanlocation); Scan integer//will continue to scan NSLog at the end of the last scan (@ "-------------------------------------1"); NSLog (@ "Scanner location:%lu", ascanner.scanlocation); Nsinteger Aninteger; result = [Ascanner scaninteger:&aninteger]; NSLog (@ "Scan succeeded:%@", [email protected] "yes": @ "NO"); NSLog (@ "Scan returned results:%ld", Aninteger); NSLog (@ "Scanner location:%lu", ascanner.scanlocation); Scan the integer//position the scanner in the first place//the scanner will start scanning by default at the end of the last scan, instead of starting at the beginning//when scanning toA character that is not an integer will stop the scan (if the position starting the scan is not an integer, the scan will be stopped directly) NSLog (@ "-------------------------------------2"); ascanner.scanlocation = 0; Position the scanner in the position NSLog (@ "Scanner location:%lu", ascanner.scanlocation); Nsinteger AnInteger2; result = [Ascanner scaninteger:&aninteger2]; NSLog (@ "Scan succeeded:%@", [email protected] "yes": @ "NO"); NSLog (@ "Scan returned results:%ld", anInteger2); NSLog (@ "Scanner location:%lu", ascanner.scanlocation); Scan floating-point number//when scanning to a character that is not an integer, the scan will stop (if the position starting the scan is not an integer, the scan will be stopped directly) NSLog (@ "-------------------------------------3"); ascanner.scanlocation = 0; Position the scanner in the position NSLog (@ "Scanner location:%lu", ascanner.scanlocation); float afloat; result = [Ascanner scanfloat:&afloat]; NSLog (@ "Scan succeeded:%@", [email protected] "yes": @ "NO"); NSLog (@ "Scan returned results:%f", afloat); NSLog (@ "Scanner location:%lu", ascanner.scanlocation); NSLog (@ "-------------------------------------4"); NSLog (@ "scanned string:%@", ascanner.string); NSLog (@ "Scanner location:%lu", ascanner.scanlocation); NSLog (@ "whether to sweepStroke to end:%@ ", [email protected]" yes ": @" NO ");</span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS development-usage of Nsscanner