ios之NSString的使用方法

时间:2022-02-26 05:17:27

1、创建常量字符串

NSString *astring = @"my name is haoyanqing!";

2、创建空的字符串,并给其赋值

NSString *astring = [[NSString alloc] init];

astring = @"This is a String!";

[astring release];

NSLog(@"astring:%@",astring);

//

NSString *astring = [[NSString alloc] init];

NSLog(@"0x%.8x", astring);

astring=@"This is a String!";

NSLog(@"0x%.8x", astring);

[astring release];

NSLog(@"astring:%@",astring);

3、initWithString方法

NSString *astring = [[NSString alloc] initWithString:@"This is a String!"];

NSLog(@"astring:%@",astring);

[astring release];