[英]How to remove special character in id and title?
i want the result as 我想要的结果是
id =Afghanistan
title=AF
inside bracket it gave the non english characters.how to solve it 括号内给出了非英文字符。如何解决
(
{
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";
}
)
It'll make everything easier if you can make sure that everything after a opening bracket can be removed. 如果您可以确保将开括号后的所有内容都可以卸下,那么它将使一切变得容易。
// 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]];
and you can remove the newlines from your countrycode like this: 您可以像这样从国家/地区代码中删除换行符:
NSString *countryCode = [@"AF\n \n" stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
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 "]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.