2011-03-12 74 views
0

我想要的结果作为如何删除标识和标题中的特殊字符?

id =Afghanistan

title=AF

内支架它给非英语characters.how解决它

(

    { 
    id = "Afghanistan (\U0627\U0641\U063a\U0627\U0646\U0633\U062a\U0627\U0646)"; 
    title = "AF\n \n"; 
}, 
    { 
    id = "Albania (Shqip\U00ebria)"; 
    title = "AL\n \n"; 
}, 
    { 
    id = "Algeria (\U0627\U0644\U062c\U0632\U0627\U0626\U0631)"; 
    title = "DZ\n \n"; 
}, 
    { 
    id = "American Samoa"; 
    title = "AS\n \n"; 
} 

) 
+0

这是一个XML解析器结果请人 – rithik

回答

0

它会让一切更容易,如果你能确保可以删除左括号后的所有内容。

// find the location of the bracket 
NSInteger bracketStart = [str rangeOfString:@"("].location; 
// get the substring to the opening bracket 
NSString *reducedStr = [str substringToIndex:bracketStart]; 
// remove whitespace at the end of the needed string 
reducedStr = [reducedStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 

,你可以从你的COUNTRYCODE这样删除换行符:

NSString *countryCode = [@"AF\n \n" stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
0
NSString* id_str = [NSString stringWithUTF8String: "Afghanistan (\u0627\u0641\u063a\u0627\u0646\u0633\u062a\u0627\u0646)\0"]; 
id_str = [[id_str componentsSeparatedByString: @"("] objectAtIndex: 0]; 

NSString* title = @"AS\n \n"; 
title = [title stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString: @"\n "]]; 
+0

,而我把它添加到它给结果与数组引号。 – rithik

+0

我删除了所有的括号子字符串,现在我只想删除“” – rithik

+0

NSString * str = [@“\”Hello \“”stringByReplacingOccurrencesOfString:@“\”“withString:@”“]; – Max