本文介绍了iPhone rangeOfString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我有这样的字符串:

HelloI have a string like this:

Results for: 123D12 
2010

2009

2008

2007

2006

YEAR: 2006 WEEK: 2 PRODIDNUM: 37911
 ACCESSKEY: FA3540B52F

2005

2004

YEAR: 2004 WEEK: 22 PRODIDNUM: 46178
 ACCESSKEY: 58B2509373

我想找出ACCESSKEY来帮助我获取十六进制数(在这种情况下为FA3540B52F和58B2509373).

and I want to spot the ACCESSKEY to help me get the hexadecimal(in this case are FA3540B52F and 58B2509373).

问题在于,当我使用rangeOfString获取访问密钥时,它只会停止到第一个!这是我的代码:

The issue is that when I use rangeOfString to get the accesskey it stops only to the first one! This is my code:

if ([strippedString rangeOfString:@"ACCESSKEY"].location != NSNotFound ) {
    NSUInteger int1=[strippedString rangeOfString:@"ACCESSKEY"].location;

    NSString *finssid = [strippedString substringWithRange:NSMakeRange(int1+11,10)];
    NSLog(@"Output = Found it %d \n",int1);

    NSLog(@"Output =%@ \n \n",finssid);    
}

我在这里做错了什么?

推荐答案

尝试一下:

NSRange searchRange = NSMakeRange(0, [strippedString length]);
BOOL keepGoing = YES;

// Find all ssid
while (keepGoing) {
    NSRange accessWord = [strippedString rangeOfString:@"ACCESSKEY" options:NSCaseInsensitiveSearch range:searchRange];
    if (accessWord.location != NSNotFound) {
        // since we have found the access key, we can assume somethings
        // ACCESSKEY: FA3540B52F
        int pos = accessWord.location + 11;
        NSString *ssid = [strippedString substringWithRange:NSMakeRange(pos, pos + 10)];

        NSLog(@"SSID: %@", ssid);

        // reset our search up a little for our next loop around
        searchRange = NSMakeRange(pos, [strippedString length] - pos);
    } else {
        keepGoing = NO;
    }
}

`

这篇关于iPhone rangeOfString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:41