如何删除空格、括号和“来自 nsarray [英] how to remove spaces, brackets and " from nsarray
问题描述
我有一个数组,我试图从 nsarray 中删除访问空格、方括号和 " 以使用 componentsSeparatedByString:@";"
I have an array where i am trying to remove the access spaces, brackets and " from the nsarray in order to use 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,5,396;39639857;29603,39867;29603,39867;29599,39892;29596,39909;295 87,39957;29571,40018;29563,40038;29563,40038;29563, 4行内的字符串代码为3956我尝试使用
componentsSeparatedByString:@";"
它不能溢出所有有空格括号和里面.
this is the output give as show there are spaces, brackets and " how could i remove them
?
As this line is juz a string inside that array "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
and i try using componentsSeparatedByString:@";"
it could not be spilt all there are spaces brackets and " inside.
推荐答案
Try stringByTrimmingCharactersInSet:
Try stringByTrimmingCharactersInSet:
NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"() \n\""];
s = [s stringByTrimmingCharactersInSet:charsToTrim];
这篇关于如何删除空格、括号和“来自 nsarray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!