zoukankan      html  css  js  c++  java
  • 根据字符串中的具体信息来找到其具体位置和长度

    #import <Foundation/Foundation.h>

    int main(int argc, const char * argv[]) {

        @autoreleasepool {

           /* NSString *str=@"apple banana pear";

           

            NSArray *array=[str componentsSeparatedByString:@" "];

            NSLog(@"%@",array);*/

     /*   //substringToIndex  从字符串开始位置,一直截到你指定位置,但是不包括你指定的位置

            NSString *str1=@"abcdefg";

         NSString *newStr1=[str1 substringToIndex:4];

            NSLog(@"%@",newStr1);

      

        //substringFromIndex  以指定位置开始(并且包括指定位置)之后的全部字符

         NSString *newstr2=[str1 substringFromIndex:4];

             NSLog(@"%@",newstr2);*/

            

        /*    //根据范围截取字符串

        NSString *str3=@"abcdefg";

            NSRange rang;

            rang.location=2;

            rang.length=3;

            

        NSString *newStr3=[str3 substringWithRange:rang];

            

            NSLog(@"%@",newStr3);*/

            

    NSString *string=@"http://localhost:8099/test/user=admin&pwd=123";

            

           NSRange rang= [string rangeOfString:@"pwd="];

            

        NSLog(@"location=%ld,length=%ld",rang.location,rang.length);

            

        NSLog(@"pwd=%@",[string substringFromIndex:rang.location+rang.length]);

            

        }

        return 0;

    }

  • 相关阅读:
    【转】逆向工程:让我们剥开软件的坚果
    分散/聚集IO(scatter/gather)及iovec结构体
    C10K并发连接_转
    AVL平衡二叉树
    软中断
    应用层timer_如何序列化timer
    应用层timer_libc_posix timer
    linux/unix 段错误捕获_转
    C/C++捕获段错误,打印出错的具体位置(精确到哪一行)_转
    linux内存查看及释放
  • 原文地址:https://www.cnblogs.com/jidezhi/p/5120736.html
Copyright © 2011-2022 走看看