componentsSeparatedByString省略由分隔符包围的子串?

时间:2013-04-11 20:36:57

标签: objective-c macos

我试图在componentsSeparatedByString

的帮助下划分用“ - ”分隔的输入
NSString *idInput = @"1-S2-1-8214685" //Actually input of a memory-rading operation

NSMutableArray *idBuf = [NSMutableArray arrayWithArray:[idInput componentsSeparatedByString:@"-"]];

然而,这似乎省略了第一个子串以及第三个子串,因为后面的idBuf包含以下内容:

idBuf = {@"",@"S2",@"",@"8214685"}

如何掌握两个缺失的子串?

整个功能:

+ (id) buildPlayerwithIdBuffer: (char*)idBuffer andPlayerName: (char*)playerName
{

NSString *idInput = [NSString stringWithUTF8String:idBuffer];
NSString *playerN = [NSString stringWithUTF8String:playerName];
NSString *uniqueServerId;

SFPlayer *resPlayer = [[self alloc]initWithPlayerName:playerN];

    NSMutableArray *idBuf = [NSMutableArray arrayWithArray:[idInput componentsSeparatedByString:@"-"]];
    //[idBuf removeObjectAtIndex:1];

    switch ([[idBuf objectAtIndex:0]characterAtIndex:0]) {
        case '1':
            [idBuf replaceObjectAtIndex:0 withObject:@"us"];
            break;
        case '2':
            [idBuf replaceObjectAtIndex:0 withObject:@"eu"];
            break;
        case '3':
            [idBuf replaceObjectAtIndex:0 withObject:@"kr"];
            break;
        case '6':
            [idBuf replaceObjectAtIndex:0 withObject:@"sg"];
            break;
        default:
            break;
    }

    uniqueServerId = [[idBuf objectAtIndex:2] stringByAppendingString:[idBuf lastObject]];

    [resPlayer setServer:[idBuf objectAtIndex:0]];
    [resPlayer setIdentifier:uniqueServerId];



return resPlayer;


}

编辑:我刚刚再次检查,idBuf [0]和idBuf [3]包含相同的值,显示为C String:

"@\xfffffffa\xfffffffb}\xffffffff\x7f"

0 个答案:

没有答案