typedef struct DATE {
? ? int y;
? ? int m;
? ? int d;
} MDate;
?//定义结构体类型
? ? struct DATE {
? ? ? ? int y;
? ? ? ? int m;
? ? ? ? int d;
? ? };
? ? struct DATE d = {2023,1,15};
? ??
? ? MDate d1= {2023,1,1};
? ? NSLog(@"%i",d1.y);
? ??
? ? //NSRange的使用
? ? NSRange ran = NSMakeRange(10, 5);
? ??
? ? NSRange ran2 = {10,8};
? ??
? ? NSRange ran1;
? ? ran1.location = 10;
? ? ran1.length = 1;
? ??
? ? NSString *ranks = NSStringFromRange(ran);
? ? NSLog(@"ran的值为%@",ranks);
? ??
? ? //NSPoint的使用
? ? NSPoint ns = NSMakePoint(10, 10);
? ? NSPoint ns2 = CGPointMake(10, 10);
? ? NSString *nss = NSStringFromPoint(ns);
? ? NSLog(@"nss的值为%@",nss);
? ??
? ? //NSSize的使用
? ? NSSize size = NSMakeSize(100, 100);
? ??
? ? //NSRect的使用
? ? NSRect re = NSMakeRect(10, 10, 100, 100
NSString *str1 = @"a string";
NSString *str2 = [[NSString alloc] initWithString:@"a string"];
[str2 release];
NSString *str3 = [[NSString alloc] initWithUTF8String:"a string"];
[str3 release];
NSString *str4 = [[NSString alloc] initWithFormat:@"test is %i",10];
[str4 release];
//从文件中读取文本
NSError *err;
NSString *str5 = [NSString stringWithContentsOfFile:@"/Users/liusir/Desktop/pdd账号1.txt" encoding:NSUTF8StringEncoding error:&err];
NSLog(@"file content >> %@",str5);
NSLog(@"err %@",[err localizedDescription]);
NSURL *nsurl = [NSURL URLWithString:@"file:///Users/liusir/Desktop/pdd账号1.txt"];
NSString *str6 = [NSString stringWithContentsOfURL:nsurl encoding:NSUTF8StringEncoding error:nil];
//写入字符串到文本
NSString *str7 = @"123456";
[str7 writeToFile:@"/Users/liusir/Desktop/test.txt" atomically:YES encoding:NSUTF8StringEncoding error:nil];
NSString *str8 = @"age is 30";
NSString *str9 = [str8 uppercaseString];//转大写
NSLog(@"%@",str9);
NSLog(@"%@",[str8 lowercaseString]);//转小写
NSLog(@"%@",[str8 capitalizedString]);//首字母大写
NSString *str10 = @"123456";
//比较字符串是否相同
NSLog(@"%i",[str8 isEqualToString:str10]);
NSComparisonResult result = [str8 compare:str10];
if(result == NSOrderedSame){
NSLog(@"same");
}else if (result == NSOrderedAscending){
NSLog(@"NSOrderedAscending");
}else if (result == NSOrderedDescending){
NSLog(@"NSOrderedDescending");
}
NSMutableString 可变字符串的使用
// NSMutableString 可变字符串的使用
NSMutableString *nsMStr = [NSMutableString stringWithString:@"123"];
NSLog(@"nsMStr %%@",nsMStr);
[nsMStr appendString:@"456"];
NSLog(@"nsMStr change %@",nsMStr);