我正在尝试在 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 字符串是:
"@\xfffffffa\xfffffffb}\xffffffff\x7f"