2017-02-04 1 views
-2

Comment puis-je appliquer uppercaseString sur NSMutableString? Dans ce code, la valeur string2 ne change pas en seconde NSLog:NSMutableString dans iOS

NSMutableString *string2=[[NSMutableString alloc]initWithCapacity:100]; 
[string2 appendFormat:@"%@ Objective C",@"Hello"]; 
NSLog(@"%@",string2); 
[string2 uppercaseString]; 
NSLog(@"%@",string2); 
+3

'uppercaseString' retourne un NSString, il n'applique pas la transformation dessus. – Larme

Répondre

0

uppercaseString ne transforme pas la chaîne actuelle en majuscules. ce qu'il fait est qu'il renvoie une chaîne majuscule transformée.

Voici le lien vers le Apple documentation à propos uppercaseString

Pour répondre à votre question de pouvoir faire une chaine2 upppercase ce que vous pouvez faire quelque chose comme ceci:

// need the mutable copy since string2 is a mutable string and uppercaseString only returns an immutable copy 
string2 = [[string2 uppercaseString]mutableCopy];