iOS development-usage of Nsscanner

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.