加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 如何在不破坏代码的情况下在Objective-C中拆分字符串

发布时间:2020-12-14 18:57:22 所属栏目:百科 来源:网络整理
导读:当我在字符串中插入换行符时,Xcode会抛出各种错误.例如,这失败了: if (newMaximumNumberOfSides 12) { NSLog(@"Invalid maximum number of sides: %i is greater than the maximum of 12 allowed.",newMaximumNumberOfSides);} 但这有效: if (newMaximumNu
当我在字符串中插入换行符时,Xcode会抛出各种错误.例如,这失败了:

if (newMaximumNumberOfSides > 12) {
    NSLog(@"Invalid maximum number of sides: %i is greater than 
            the maximum of 12 allowed.",newMaximumNumberOfSides);
}

但这有效:

if (newMaximumNumberOfSides > 12) {
    NSLog(@"Invalid maximum number of sides: %i is greater than the maximum of 12 allowed.",newMaximumNumberOfSides);
}

我更喜欢前者,因为它看起来更清晰(较短的线条),但代码中断了.处理这个问题的最佳方法是什么? (子问题:这是在任何语法指南中引用的吗?我搜索了所有书籍的“换行符”都没有效果.)

解决方法

所有这些应该工作:

NSString *s = @"this" 
        @" is a" 
        @" very long" 
        @" string!";

    NSLog(s);


    NSString *s1 = @"this" 
        @" is a" 
        @" very long" 
        @" string!";

    NSLog(s1);

    NSString *s2 = @"this"
        " is a"
        " very long"
        " string!";

    NSLog(s2);

    NSString *s3 = @"this
 is a
 very long
 string!";

    NSLog(s3);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读