将英文句子 按单词拆分 并获取range、index

    iOS系统方法。

将英文句子 按单词拆分 并获取range、index


NSString * str2 = @"Do the any the additional setup after loading the view, typically from a nib.";
    [str2 enumerateSubstringsInRange:NSMakeRange(0, str2.length-1) options:NSStringEnumerationByWords usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
        NSLog(@"substring:%@",substring);
        NSLog(@"substringRange:%@",NSStringFromRange(substringRange));
    }];



NSLog:


substring:Do

substringRange:{0, 2}

substring:the

substringRange:{3, 3}

substring:any

substringRange:{7, 3}

substring:the

substringRange:{11, 3}

substring:additional

substringRange:{15, 10}

substring:setup

substringRange:{26, 5}

substring:after

substringRange:{32, 5}

substring:loading

substringRange:{38, 7}

substring:the

substringRange:{46, 3}

substring:view

substringRange:{50, 4}

substring:typically

substringRange:{56, 9}

substring:from

substringRange:{66, 4}

substring:a

substringRange:{71, 1}

substring:nib

substringRange:{73, 3}


你可能感兴趣的:(iOS控件自定义及使用技巧)