//字符串 //////NSString类实例方法 NSLog(@"输入的网址为:%@",str);//查值 int str_len = [str length];//求其长度 NSLog(@"长度为:%d字节",str_len); char c = [str characterAtIndex:11];//找字符 NSLog(@"%c",c); //[str description] //字符串(格式化)拼接 NSMutableString * str_ = [[NSMutableString alloc] initWithFormat:@"+++iphone IOS"]; NSLog(@"%@",[str stringByAppendingFormat:@"%@",str_]); //求子串 NSLog(@"%@",[str substringFromIndex:11]);//求后串。求第11个字符以及之后的字符串,包括第11个字符。 NSLog(@"%@",[str substringToIndex:11]);//求前串。求第11个字符之前的字符串,不包括第11个字符。 //字符串转换为基本类型 // -(double) doubleValue -(int) intValue -(float) floatValue -(BOOL) boolValue NSLog(@"%f,%d,%f,%d",[str doubleValue],[str intValue],[str floatValue],[str boolValue]); //单词首字母大写,全小写,全大写 //– capitalizedString – lowercaseString – uppercaseString NSLog(@"%@,%@,%@",[str_ capitalizedString],[str_ lowercaseString],[str_ uppercaseString]); //比较字符串是否相等 NSLog(@"%d",[str isEqualToString:str_]); //比较字符串大小 //-(NSComparisonResult)compare:(NSString *) str // compare方法会返回三种NSComparisonResult类型的值 // NSOrderedAscending = -1 //递增,升序 // NSOrderedSame = 0 //相同 // NSOrderedDescending = 1 //递减 //例子: NSMutableString * tr1 = [[NSMutableString alloc] initWithFormat:@"1"]; NSMutableString * tr2 = [[NSMutableString alloc] initWithFormat:@"2"]; NSLog(@"%d",[tr1 compare:tr2]);
相关文章: