How to append a string to NSMutableString

前端 未结 5 1752
自闭症患者
自闭症患者 2021-01-01 14:50

i\'m an absolute newbie with objective-c

with this code

NSMutableString *teststring;
[teststring appendString:@\"hey\"];
NSLog(teststring);
         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 15:23

    Sample:

    NSMutableString *buffer = [[NSMutableString alloc] init]; // retain count = 1. Because of the "alloc", you have to call a release later
    
    [buffer appendString:@"abc"];
    NSLog(@"1 : %@", buffer);
    [buffer appendString:@"def"];
    NSLog(@"2 : %@", buffer);
    
    [buffer release]; // retain count = 0 => delete object from memory
    

提交回复
热议问题