gpt4 book ai didi

ios - 如何在iOS中从String的服务器响应中以数字格式显示新行

转载 作者:行者123 更新时间:2023-12-01 18:05:55 25 4
gpt4 key购买 nike

我得到的服务器响应是:“我们将组织放置在某些位置。1.第一次测试2.第二测试3.第三测试4.第四测试。选择一个以获得更多信息”;

我正在研究 Objective-C ,并试图在UILabel中显示,但问题是我想显示为段落。就像通过跟随拆分字符串一样。

我们的组织正在追踪某些地点。

  • 第一次测试
  • 第二次测试
  • 第三次测试
  • 第四个测试
    选择一个以获得更多信息。

  • 上面是一个示例,但是数据是完全动态的,并且不知道响应字符串中会有多少个点。

    任何人对此都有想法。

    最佳答案

    尝试这个 :

           NSString *str = @"We've organizations in following something locations. 1. First test 2. Second test 3. Third test 4. Fourth test.";
    str = [str stringByReplacingOccurrencesOfString:@"1." withString:@"\n 1."];
    str = [str stringByReplacingOccurrencesOfString:@"2" withString:@"\n 2"];
    str = [str stringByReplacingOccurrencesOfString:@"3" withString:@"\n 3"];
    str = [str stringByReplacingOccurrencesOfString:@"4" withString:@"\n 4"];
    yourlbl.text = str;

    动态方式
    NSString *str = @"We've organizations in following something locations. 1. First test 2. Second test 3. Third test 4. Fourth test.";
    NSCharacterSet *numberCharset = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    NSScanner *theScanner = [NSScanner scannerWithString:str];
    while (![theScanner isAtEnd]) {
    // Eat non-digits and negative sign
    [theScanner scanUpToCharactersFromSet:numberCharset
    intoString:NULL];
    int aInt;
    if ([theScanner scanInt:&aInt]) {
    str = [str stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%d",aInt] withString:[NSString stringWithFormat:@"\n %d",aInt]];
    }
    }

    关于ios - 如何在iOS中从String的服务器响应中以数字格式显示新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44699408/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com