-3

How can I apply uppercaseString on NSMutableString? In this code the value in string2 is not changing in second NSLog:

NSMutableString *string2=[[NSMutableString alloc]initWithCapacity:100];
[string2 appendFormat:@"%@ Objective C",@"Hello"];
NSLog(@"%@",string2);
[string2 uppercaseString];
NSLog(@"%@",string2);
Grisha Levit
  • 8,194
  • 2
  • 38
  • 53

1 Answers1

0

uppercaseString does not transform the current string to uppercase. what it does is that it returns a transformed uppercase string.

Here is the link to the Apple documentation about uppercaseString

so to answer your question to be able to make string2 an upppercase what you can do is something like this:

// need the mutable copy since string2 is a mutable string and uppercaseString only returns an immutable copy
string2 = [[string2 uppercaseString]mutableCopy]; 
Joshua
  • 2,432
  • 1
  • 20
  • 29