每日一练:OC中的关于NSString常用的几个方法


#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 China

2018-03-10 22:21:23.753476+0800 TOCObjectivea[53935:13718634] Now the string is The time is 2018-03-10 14:21:23 +0000

2018-03-10 22:21:23.753548+0800 TOCObjectivea[53935:13718634] The String length is 16

2018-03-10 22:21:23.753618+0800 TOCObjectivea[53935:13718634] Now the String is: THIS IS AN APPLE

2018-03-10 22:21:23.753665+0800 TOCObjectivea[53935:13718634] The two Strings are not same

Program ended with exit code: 0



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值