zoukankan      html  css  js  c++  java
  • 【代码笔记】iOS-字符串的分割

    一,代码。

    复制代码
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        self.title=@"字符串的分割";
        
        
        //一般的字符串的解析
        NSString *string = @"One,Two,Three,Four";
        NSLog(@"string:%@",string);
        NSArray *array = [string componentsSeparatedByString:@","];
        NSLog(@"array:%@",array);
       
        
        //两个json数组连在一起的解析
        NSString *jsonStringOther=[NSString stringWithFormat:@"{"name":"李华", "sex":"女", "age":"20" }
    {"name":"李华", "sex":"女", "age":"20" }"];
        NSLog(@"-----jsonStringOther---%@",jsonStringOther);
        NSArray *jsonArray = [jsonStringOther componentsSeparatedByString:@"
    "];
        NSLog(@"jsonArray:%@",jsonArray);
        
    }
    复制代码

     

    二,输出。

    复制代码
    2015-10-22 11:13:21.872 字符串的分割[4057:112931] string:One,Two,Three,Four
    2015-10-22 11:13:21.873 字符串的分割[4057:112931] array:(
        One,
        Two,
        Three,
        Four
    )
    2015-10-22 11:13:21.873 字符串的分割[4057:112931] -----jsonStringOther---{"name":"李华", "sex":"女", "age":"20" }
    {"name":"李华", "sex":"女", "age":"20" }
    2015-10-22 11:13:21.873 字符串的分割[4057:112931] jsonArray:(
        "{"name":"U674eU534e", "sex":"U5973", "age":"20" }",
        "{"name":"U674eU534e", "sex":"U5973", "age":"20" }"
    )
    复制代码

     

     

     
     
  • 相关阅读:
    Java学习-IO流-read()和write()详解
    JAVA中String类常用构造方法
    java的System.exit(0)和System.exit(1)区别。
    Eclipse快捷键大全
    Java Arraylist的遍历
    Java Map的遍历
    C++求最大公约数,最小公倍数
    C++sort使用实例
    [Project Euler] 题目汇总
    [leetcode]做过的题的目录
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5755515.html
Copyright © 2011-2022 走看看