1

我有一个数组,我试图从 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"
)

这是输出,因为显示有空格、括号和“我怎么能删除它们?因为这条线是该数组内的一个字符串"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;295‌​87,39957;29571,40018;29563,40038;29560,40043" this line is a string inside the path array,我尝试使用componentsSeparatedByString:@";"它不能被溢出所有有空格括号和”里面。

4

3 回答 3

3

试试 stringByTrimmingCharactersInSet:

NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"()  \n\""];
s = [s stringByTrimmingCharactersInSet:charsToTrim];
于 2012-08-16T11:48:28.480 回答
0

尝试使用:

s = [s stringByReplacingOccurrencesOfString:@";"
                                     withString:@""];
于 2012-08-16T13:04:44.403 回答
0

它为您分隔数字,您可以将它们作为 ieNSInteger值使用。

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);
}
于 2012-08-16T13:11:30.523 回答