zoukankan      html  css  js  c++  java
  • IOS学习笔记39--NSString各种语法的使用

    今天就NSString的各种语法学习学习,以后慢慢补充;

    1.字符串的遍历                  

     

         NSString *string = @"CHENGWULI";             

        //字符串的长度

        int count = [string length];

        NSLog(@"字符串的长度是%d",count);

        //遍历字符串中的每一个字符

        for(int i =0; i < count; i++){

            char c = [string characterAtIndex:i];

            NSLog(@"字符串第 %d位为 %c",i,c);

        }

    2.字符串的比较

     

        NSString *str0 = @"lichengwu";

        NSString *str1 = @"lichengwu-A";

        //字符串完全相等比较

        if([str0 isEqualToString:str1]){

            NSLog(@"字符串完全相等");

        }

        else{

             NSLog(@"字符串不相等");

        }

        //字符串以开头比较

        if([str0 hasPrefix:@"li"]){

            NSLog(@"字符串str0li开头");

        }

        

        //字符串以结尾比较

        if([str1 hasSuffix:@"wu-A"]){

            NSLog(@"str1字符串以wu-A结尾");

        }






  • 相关阅读:
    十一作业
    11.20
    11.13 第十二次、
    11.13 第十一次、
    11.06第十次、
    11.06第九次、
    10.30
    10.23
    10.16
    10.9
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3239000.html
Copyright © 2011-2022 走看看