NSPoint
#pragma mark - 结构体类型 NSPoint...
NSPoint point = NSMakePoint(1.2, 1.3);
NSLog(@"point = %@",NSStringFromPoint(point));
NSRect rect = NSMakeRect(1, 1, 100, 100);
NSLog(@"rect = %@",NSStringFromRect(rect));
NSRange range = NSMakeRange(3, 3);
NSLog(@"range = %@",NSStringFromRange(range));
NSSize size = NSMakeSize(100, 100);
NSLog(@"size = %@",NSStringFromSize(size));
// NSRect rect = NSMakeRect(1, 1, 10, 10);
// NSLog(@"rect = %@",NSStringFromRect(rect));
#pragma mark - 使用NSValue将简单、复杂数据类型封装为对象
//封装
NSValue *pointValue = [NSValue valueWithPoint:point];
NSLog(@"value1 = %@",pointValue);
NSValue *rectValue = [NSValue valueWithRect:rect ];
NSLog(@"value2 = %@",rectValue);
//解封装
NSPoint point1 = [pointValue pointValue];
NSRect rect1 = [rectValue rectValue];
NSNumber 对象初始化、使用NSNumberFormatter对NSNumber与NSString转化
#pragma mark - 数值类型 NSNumber 对象初始化、使用NSNumberFormatter对NSNumber与NSString转化
NSInteger number = 135670;
NSNumber *number1 = [NSNumber numberWithInteger:number];
//解封装
NSInteger a = [number1 integerValue];
NSLog(@"%ld", (long)a);
NSInteger age = 10;
NSNumber *newNumber = @(age);//@100,@(100),@(age)
NSLog(@"%@",newNumber);
// @'x',@1.33,@YES
//创建一个格式转换器
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
//设置格式
[formatter setNumberStyle:NSNumberFormatterSpellOutStyle];
NSString *string = [formatter stringFromNumber:number1];
NSLog(@"string = %@",string);
NSString字符串处理 增删查改…
1.各种初始化
//最简初始化方式
NSString *string = @"hello world";
NSLog(@"string = %@",string);
//常规初始化
NSString *string1 = [[NSString alloc] initWithFormat:@"hello %@",string];
NSLog(@"string1 = %@",string1);
NSString *string2 = [[NSString alloc] initWithString:string];
//便利构造初始化
NSString *string3 = [NSString stringWithFormat:@"hello"];
NSLog(@"string3 = %@",string3);
2.字符串拼接 stringByAppend… stringByAppendingFormat
NSString *string = @"hello";
//一般的字符串拼接方法
NSString *appendString = [string stringByAppendingString:@" world"];
NSLog(@"appendStr = %@",appendString);
//格式字符串的拼接方法
NSString *newAppendString = [string stringByAppendingFormat:@"%@",@"newWorld"];
NSLog(@"newAppendStr = %@",newAppendString);
//初始化拼接
NSString *append1String = [NSString stringWithFormat:@"%@%@",string,@"world"];
NSLog(@"AppendStr1 = %@",append1String);
3.字符串截取 subString…
NSString *string = [[NSString alloc] initWithFormat:@"hello world"];
NSString *subString1 = [string substringFromIndex:6];
NSLog(@"sub1 = %@",subString1);
NSString *subString2 = [string substringToIndex:5];
NSLog(@"sub2 = %@",subString2);
// NSRange range = NSMakeRange(3, 4);
NSRange range = {3, 4};
NSLog(@"range = %@",NSStringFromRange(range));
NSString *subString3 = [string substringWithRange:NSMakeRange(3, 4)];
NSLog(@"sub3 = %@",subString3);
4.字符串的长度
NSString *string = [[NSString alloc] initWithFormat:@"hello world"];
NSUInteger length = string.length;
//等价
NSUInteger length = [string length];
5.字符串查询
NSString *string = [NSString stringWithFormat:@"www.baidu.com"];
//查询头部
BOOL flag = [string hasPrefix:@"www."];
if (flag == YES) {
NSLog(@"find");
}else{
NSLog(@"no find");
}
//查询尾部
BOOL flag1 = [string hasSuffix:@".com"];
if (flag1) {
NSLog(@"find");
}else{
NSLog(@"no find");
}
//查找字符串的位置:rangeOfString
NSRange range = [string rangeOfString:@"baidu"];
if (range.location != NSNotFound && range.length > 0) {
NSLog(@"find,location:%@",NSStringFromRange(range));
}else{
NSLog(@"no find");
}
6.字符串替换 stringByReplacing…
NSString *string = [NSString stringWithFormat:@"www.baidu.com"];
NSString *replaceString = [string stringByReplacingCharactersInRange:NSMakeRange(3, 1) withString:@" "];
NSLog(@"replaceStr = %@",replaceString);
7.字符串比较 isEqualTo… compare
NSString *string1 = @"aBc";
NSString *string2 = @"Abc";
if ([string1 isEqualToString:string2]) {
NSLog(@"equal");
}else{
NSLog(@"no equal");
}
NSComparisonResult result = [string1 compare:string2];
/*
NSOrderedAscending = -1L, 升序
NSOrderedSame = 0, 相等
NSOrderedDescending = 1 降序
*/
/*
if (result == -1) {
NSLog(@"前一个数比后一个数小");
}else if (result == 0){
NSLog(@"相等");
}else{
NSLog(@"前一个数比后一个数大");
}
*/
if (result == NSOrderedAscending) {
NSLog(@"前一个数比后一个数小");
}else if (result == NSOrderedSame){
NSLog(@"相等");
}else{
NSLog(@"前一个数比后一个数大");
}
数值转换 integerValue…
NSString *string1 = @"5000.6";
NSString *string2 = @"6000";
NSInteger number1 = [string1 floatValue];
NSInteger number2 = [string2 integerValue];
NSInteger sum = number1 + number2;
NSString *moneyString = [NSString stringWithFormat:@"%d",5000];
大小写转换 uppercaseString、lowercaseString、capitalizedString 首字母大写
NSString *string1 = @"aBc";
NSLog(@"%@",[string1 lowercaseString]);
SMutableString可变字符串处理
“`
// //常规初始化方法
NSMutableString *mutableString = [[NSMutableString alloc] initWithFormat:@"hello"];
//便利构造初始化
NSMutableString *mutableString1 = [NSMutableString stringWithFormat:@"world"];
// 插入字符串"00000"
[mutableString insertString:@"00" atIndex:2];
NSLog(@"mutableString = %@",mutableString);
// 删除
[mutableString deleteCharactersInRange:NSMakeRange(2, 2)];
NSLog(@"mutableString = %@",mutableString);
//替换ll
[mutableString replaceCharactersInRange:NSMakeRange(2, 2) withString:@"00"];
NSLog(@"mutableString = %@",mutableString);
```