我有字符串
测试字符串是= = = = =>{"名称":"0","年龄":"0","性":"0"、"重量":"0"}
myArray[0]="Name";
myArray[1]="Age";
myArray[2]="Sex";
myArray[3]="weight";
请帮助我破解这个东西。
Try
NSArray *arrComponents = [str componentsSeparatedByString:@","];
NSMutableArray *arrmFilter = [[NSMutableArray alloc] init];
for(int i = 0; i < [arrComponents count] ;i++)
{
NSString *str = [arrComponents objectAtIndex:i];
str = [str stringByReplacingOccurrencesOfString:@":" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@""" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"{" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"}" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"0" withString:@""];
[arrmFilter addObject:str];
}
NSLog(@"Filtered array = %@", arrmFilter);
这个怎么样?
NSArray *yourNewArray = [testString componentsSeparatedByString:","];
我不是100%确定你的测试字符串,但这个方法返回一个NSArray
对象基于你的特定分隔符在你的字符串。
试试这个
//以下代码返回包含4个字符串对象的数组,但包含字符{,},:,0
NSArray *arr=[str componentsSeparatedByString:@","];
NSMutableArray *arrNew = [[NSMutableArray alloc] init];
//从所有数组对象中删除那些不寻常的字符
for(int i = 0;i <[arr count] ;i++)
{
NSString *str = [arrComponents objectAtIndex:i];
str = [str stringByReplacingOccurrencesOfString:@":" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@""" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"{" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"}" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"0" withString:@""];
[arrNew addObject:str];
}