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

NSString+NSMutableString+NSValue+NSAraay用法汇总

 2010-09-16 23:54:00 来源:WEB开发网   
核心提示:BOOL result = [astring01 compare:astring02options:NSCaseInsensitiveSearch | NSNumericSearch] = = NSOrderedSame;NSLog(@"result:%d",result);//NSCaseInse

BOOL result = [astring01 compare:astring02

options:NSCaseInsensitiveSearch | NSNumericSearch] = = NSOrderedSame;

NSLog(@"result:%d",result);

//NSCaseInsensitiveSearch:不区分大小写比较 NSLiteralSearch:进行完全比较,区分大小写 NSNumericSearch:比较字符串的字符个数,而不是字符值。

/*----------------改变字符串的大小写----------------*/

NSString *string1 = @"A String";

NSString *string2 = @"String";

NSLog(@"string1:%@",[string1 uppercaseString]);//大写

NSLog(@"string2:%@",[string2 lowercaseString]);//小写

NSLog(@"string2:%@",[string2 capitalizedString]);//首字母大小

/*----------------在串中搜索子串 ----------------*/

NSString *string1 = @"This is a string";

NSString *string2 = @"string";

NSRange range = [string1 rangeOfString:string2];

int location = range.location;

int leight = range.length;

NSString *astring = [[NSString alloc] initWithString:[NSString stringWithFormat:@"Location:%i,Leight:%i",location,leight]];

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

[astring release];

/*----------------抽取子串 ----------------*/

//-substringToIndex: 从字符串的开头一直截取到指定的位置,但不包括该位置的字符

NSString *string1 = @"This is a string";

NSString *string2 = [string1 substringToIndex:3];

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

//-substringFromIndex: 以指定位置开始(包括指定位置的字符),并包括之后的全部字符

NSString *string1 = @"This is a string";

NSString *string2 = [string1 substringFromIndex:3];

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

//-substringWithRange: //按照所给出的位置,长度,任意地从字符串中截取子串

NSString *string1 = @"This is a string";

NSString *string2 = [string1 substringWithRange:NSMakeRange(0, 4)];

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

上一页  1 2 3 4 5 6 7 8  下一页

Tags:NSString NSMutableString NSValue

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