我有一个数组,我试图删除访问空格,括号和“来自nsarray以便使用componentsSeparatedByString:@";"
NSArray *paths = [dic valueForKey:@"PATH"];
for(NSString *s in paths)
{
NSLog(@"String: %@", s);
}
String: (
"29858,39812;29856,39812;29800,39819;29668,39843;29650,39847;29613,39855;29613,39855;29613,39856;29605,39857;29603,39867;29603,39867;29599,39892;29596,39909;29587,39957;29571,40018;29563,40038;29560,40043"
)
这是输出给出显示有空格,括号和“我怎么能删除它们
?
由于此行是juz,该数组"29858,39812;29856,39812;29800,39819;29668,39843;29650,39847;29613,39855;29613,39855;29613,39856;29605,39857;29603,39867;29603,39867;29599,39892;29596,39909;29587,39957;29571,40018;29563,40038;29560,40043" this line is a string inside the path array
内的一个字符串,我尝试使用componentsSeparatedByString:@";"
,所有空格括号和“内部”都无法溢出。
答案 0 :(得分:3)
尝试stringByTrimmingCharactersInSet:
NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"() \n\""];
s = [s stringByTrimmingCharactersInSet:charsToTrim];
答案 1 :(得分:0)
尝试使用:
s = [s stringByReplacingOccurrencesOfString:@";"
withString:@""];
答案 2 :(得分:0)
它为您分隔数字,您可以使用它们作为NSInteger
值。
NSString *_inputString = @"29858,39812;29856,39812;29800,39819;29668,39843;29650,39847;29613,39855;29613,39855;29613,39856;29605,39857;29603,39867;29603,39867;29599,39892;29596,39909;29587,39957;29571,40018;29563,40038;29560,40043";
NSString *_setCommonSeparator = [_inputString stringByReplacingOccurrencesOfString:@";" withString:@","];
NSArray *_separetedNumbers = [_setCommonSeparator componentsSeparatedByString:@","];
for (NSString *_currentNumber in _separetedNumbers) {
NSInteger _integer = [_currentNumber integerValue];
NSLog(@"number : %d", _integer);
}