我目前收到这样的字符串:
@"Sam|26,Hannah|22,Adam|30,Carlie|32,Jan|54"
Run Code Online (Sandbox Code Playgroud)
我这样拆分它:
testArray = [[NSArray alloc] init];
NSString *testString = [[NSString alloc] initWithFormat:@"Sam|26,Hannah|22,Adam|30,Carlie|32,Jan|54,Steve|56,Matty|24,Bill|30,Rob|30,Jason|33,Mark|22,Stuart|54,Kevin|30"];
testArray = [testString componentsSeparatedByString:@","];
dict = [NSMutableDictionary dictionary];
for (NSString *s in testArray) {
testArray2 = [s componentsSeparatedByString:@"|"];
[dict setObject:[testArray2 objectAtIndex:1] forKey:[testArray2 objectAtIndex:0]];
}
Run Code Online (Sandbox Code Playgroud)
我现在将收到这样的字符串:
@"Sam|26|Developer,Hannah|22|Team Leader,Adam|30|Director,Carlie|32|PA,Jan|54|Cleaner"
Run Code Online (Sandbox Code Playgroud)
我可以(以及如何)使用与上面相同的方法使用"|"多次分隔字符串 分隔器?
我目前正在接收一个文件并将其存储到NSString中.然后我从字符串中创建一个数组并在TableView中显示它.这在一定程度上起作用.我目前正在接收这样的数据:
CompanyName | AccountCode\r \nCompanyName | AccountCode\r \nCompanyName | AccountCode\r \n等等...
在我正在做的那一刻:
NSString *dataString = [NSString stringWithContentsOfURL:url encoding:nil error:nil];
myArray = [dataString componentsSeparatedByString:@"\r\n"];
Run Code Online (Sandbox Code Playgroud)
它显示数据为:
CompanyName | AccountCode CompanyName | AccountCode CompanyName | AccountCode
我的问题是:我可以将"dataString"拆分为二维数组吗?或者我应该创建2个数组(一个使用CompanyName,一个使用AccountCode).我该怎么做?
谢谢
编辑:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
if (testArray.count …Run Code Online (Sandbox Code Playgroud)