NSUTF16StringEncoding = NSUnicodeStringEncoding, /* An alias for NSUnicodeStringEncoding */ NSUTF16BigEndianStringEncoding = 0x90000100, /* NSUTF16StringEncoding encoding with explicit endianness specified */ NSUTF16LittleEndianStringEncoding = 0x94000100, /* NSUTF16StringEncoding encoding with exp...
NSString *string2; string2 = [NSString stringWithFormat: @"hello%d",5]; if([string1 isEqualToString:string2]) { NSLog(@"They are same!"); } 1. 2. 3. 4. 5. 6. 7. 8. 9. compare:用来比较两个字符串,将接收对象和传递来的字符串进行比较,返回一个NSComparisonResult(就是一个enum型数...
} else if ([string1 compare:string2] == NSOrderedAscending){ NSLog(@"%@ 小于 %@", string1, string2); } else if ([string1 compare:string2] == NSOrderedDescending){ NSLog(@"%@ 大于 %@", string1, string2); } // 5.2 高级比較compare:options:返回NSComparisonResult(enum)型数据。小于返...
NSString篇: 1.字符串连接 1NSString *beijing =@"北京";2NSString *welcome = [beijing stringByAppendingString:@"欢迎你"];//字符串连接3NSLog(@"%@",welcome); //两种效果相同的字符串连接NSString *str22 = [str20 stringByAppendingFormat:@"%@",str21]; NSString*str23 = [str20 stringByApp...
enum _NSComparisonResult { NSOrderedAscending = -1, // string01 小于 string02 NSOrderedSame, string01 等于 string02 NSOrderedDescending string01 大于 string02 }; /---改变字符串的大小写---/ NSString *string1 = @Hello World"; NSString *string2 = @"World"; 1. upper...
常见的NSString和NSMutableString方法: [plain]view plaincopy +(id) stringWithContentsOfFile:path encoding:enc error:err 创建一个新字符串并将其设置为path指定的文件的内容,使用字符编码enc,如果非零,则返回err中错误 +(id) stringWithContentsOfURL:url encoding:enc error:err ...
typedefNS_ENUM(NSInteger,TestType){TestTypeA=0,TestTypeB,TestTypeC}; 原有转换方法: +(NSString*)getTestTypeString:(TestType)t{NSString*result=nil;switch(t){caseTestTypeA:result=@"TypeA";break;caseTestTypeB:result=@"TypeB";break;caseTestTypeC:result=@"TypeC";break;default:result=@"...
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 9, 0, ObjCRuntime.PlatformArchitecture.All, null)] [ObjCRuntime.Introduced(ObjCRuntime.PlatformName.MacOSX, 10, 11, ObjCRuntime.PlatformArchitecture.All, null)] public enum NSStringTransform ...
20. NSString简单细说(二十)—— 获取字符串的数值 这一篇我们说一下字符串与编码。 字符串与编码 一、+ (NSStringEncoding)stringEncodingForData:(NSData *)data encodingOptions:(NSDictionary<NSStringEncodingDetectionOptionsKey,id> *)opts convertedString:(NSString * _Nullable *)string usedLossyConversion...
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS,9,0, ObjCRuntime.PlatformArchitecture.All, null)] [ObjCRuntime.Introduced(ObjCRuntime.PlatformName.MacOSX,10,11, ObjCRuntime.PlatformArchitecture.All, null)]publicenumNSStringTransform