开发者

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 "]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜