2011-03-12 4 views
0

je veux le résultat queComment supprimer un caractère spécial dans id et title?

id =Afghanistan

title=AF

l'intérieur support lui a donné le characters.how non anglais pour le résoudre

(

    { 
    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

c'est un résultat de l'analyseur XML s'il vous plaît tout le monde – rithik

Répondre

0

Il va tout faire plus facile si vous pouvez assurez-vous que tout après un support d'ouverture peut être retiré.

// 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]]; 

et vous pouvez supprimer les sauts de ligne de votre countrycode comme ceci:

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

alors que je l'ajoute au tableau, il a donné le résultat comme avec citations – rithik

+0

j'ai enlevé toutes les parenthèses sous-chaîne et maintenant je veux seulement supprimer "" – rithik

+0

NSString * str = [@ "\" Bonjour \ "" stringByReplacingOccurrencesOfString: @ "\" "withString: @" "]; – Max

Questions connexes