WEB开发网
开发学院手机开发iPhone 开发 NSString+NSMutableString+NSValue+NSAraay用法汇... 阅读

NSString+NSMutableString+NSValue+NSAraay用法汇总

 2010-09-16 23:54:00 来源:WEB开发网   
核心提示://一、NSString/*创建字符串的方法*///1、创建常量字符串,NSString *astring = @"This is a String!";//2、创建空字符串,NSString+NSMutableString+NSValue+NSAraay用法汇总,给予赋值,NSString *as

//一、NSString

/*----------------创建字符串的方法----------------*/

//1、创建常量字符串。

NSString *astring = @"This is a String!";

//2、创建空字符串,给予赋值。

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

astring = @"This is a String!";

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

[astring release];

//3、在以上方法中,提升速度:initWithString方法

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

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

[astring release];

//4、用标准c创建字符串:initWithCString方法

char *Cstring = "This is a String!";

NSString *astring = [[NSString alloc] initWithCString:Cstring];

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

[astring release];

//5、创建格式化字符串:占位符(由一个%加一个字符组成)

int i = 1;

int j = 2;

NSString *astring = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%d.This is %i string!",i,j]];

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

[astring release];

//6、创建临时字符串

NSString *astring;

astring = [NSString stringWithCString:"This is a temporary string"];

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

/*----------------从文件读取字符串:initWithContentsOfFile方法 ----------------*/

NSString *path = @"astring.text";

NSString *astring = [[NSString alloc] initWithContentsOfFile:path];

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

[astring release];

/*----------------写字符串到文件:writeToFile方法 ----------------*/

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

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

NSString *path = @"astring.text";

[astring writeToFile: path atomically: YES];

[astring release];

1 2 3 4 5 6  下一页

Tags:NSString NSMutableString NSValue

编辑录入:coldstar [复制链接] [打 印]
赞助商链接