每日一练:OC中的关于NSString常用的几个方法
2018-03-10 22:23
477 查看
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here...
//直接赋值 NSString *myCountry = @"My Country is China"; NSLog(@"The sentence is %@ \n", myCountry);
//赋值使用特定的格式 NSDate *now = [NSDate date]; NSString *theDateNow = [NSString stringWithFormat:@"The time is %@", now]; NSLog(@"Now the string is %@", theDateNow); //NSString 一些常用方法 NSString *orignalString = @"This is an Apple"; //Check the length NSUInteger stringlen = [orignalString length]; NSLog(@"The String length is %lu \n", stringlen); //Change to Upper Cases NSString *upperString = [orignalString uppercaseString]; NSLog(@"Now the String is: %@ \n", upperString); NSString *secondString = @"This is an apple"; if ([orignalString isEqualToString:secondString]) { NSLog(@"The two Strings are same"); } else { NSLog(@"The two Strings are not same"); } } return 0;}
Result:
2018-03-10 22:21:23.750888+0800 TOCObjectivea[53935:13718634] The sentence is My Country is China2018-03-10 22:21:23.753476+0800 TOCObjectivea[53935:13718634] Now the string is The time is 2018-03-10 14:21:23 +00002018-03-10 22:21:23.753548+0800 TOCObjectivea[53935:13718634] The String length is 162018-03-10 22:21:23.753618+0800 TOCObjectivea[53935:13718634] Now the String is: THIS IS AN APPLE2018-03-10 22:21:23.753665+0800 TOCObjectivea[53935:13718634] The two Strings are not sameProgram ended with exit code: 0
int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here...
//直接赋值 NSString *myCountry = @"My Country is China"; NSLog(@"The sentence is %@ \n", myCountry);
//赋值使用特定的格式 NSDate *now = [NSDate date]; NSString *theDateNow = [NSString stringWithFormat:@"The time is %@", now]; NSLog(@"Now the string is %@", theDateNow); //NSString 一些常用方法 NSString *orignalString = @"This is an Apple"; //Check the length NSUInteger stringlen = [orignalString length]; NSLog(@"The String length is %lu \n", stringlen); //Change to Upper Cases NSString *upperString = [orignalString uppercaseString]; NSLog(@"Now the String is: %@ \n", upperString); NSString *secondString = @"This is an apple"; if ([orignalString isEqualToString:secondString]) { NSLog(@"The two Strings are same"); } else { NSLog(@"The two Strings are not same"); } } return 0;}
Result:
2018-03-10 22:21:23.750888+0800 TOCObjectivea[53935:13718634] The sentence is My Country is China2018-03-10 22:21:23.753476+0800 TOCObjectivea[53935:13718634] Now the string is The time is 2018-03-10 14:21:23 +00002018-03-10 22:21:23.753548+0800 TOCObjectivea[53935:13718634] The String length is 162018-03-10 22:21:23.753618+0800 TOCObjectivea[53935:13718634] Now the String is: THIS IS AN APPLE2018-03-10 22:21:23.753665+0800 TOCObjectivea[53935:13718634] The two Strings are not sameProgram ended with exit code: 0
相关文章推荐
- 每日一练: OC中的NSString及常用的几个方法
- OC中关于日期的常用方法以及注意事项
- OC NSString 常用方法
- OC中NSString 的常用方法
- OC学习 第五章 NSString和NSMutablestring的一些常用方法
- OC_NSString的常用方法
- 爬爬爬之路:OC语言(四) NSString NSSArray NSValue常用方法介绍
- oc-Foundation框架-NSString-常用方法-路径相关
- OC中的NSNumber、NSArray、NSString的常用方法
- OC中的NSNumber、NSArray、NSString的常用方法
- Android关于百度地图开发的几个常用方法
- 【Objective-C】OC中字符串(NSString)的基本概念和常用处理方法
- oc-Foundation框架-NSString-常用方法-路径相关-拓展名
- OC中的NSNumber、NSArray、NSString的常用方法
- OC中NSString 的常用方法 (转载)
- 【Objective-C】OC中字符串(NSString)的基本概念和常用处理方法
- oc-Foundation框架-NSString-常用方法-普通类型
- OC关于NSString和NSMutableString方法的使用
- iOS-OC-基础-NSString常用方法
- OC中关于几个判断对象归属及消息可用性的方法