gpt4 book ai didi

iphone - Objective-C - 连接由管道分隔的字符串

转载 作者:行者123 更新时间:2023-12-03 20:26:06 24 4
gpt4 key购买 nike

我想循环遍历数组字符串并将它们添加到 NSString通过以下方式:

NSMutableArray *emailsArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];

for (id email in emailsArray {
NSString *emails = ??;
}

最后的NSString应如下所示:

NSString *emails = @"One|Two|Three";

最佳答案

为此使用[emailsArray ComponentsJoinedByString:@"|"]

示例:

NSMutableArray *emailsArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
NSString *emails = [emailsArray componentsJoinedByString:@"|"];

这里您将拥有电子邮件 = @"One|Two|Three"

关于iphone - Objective-C - 连接由管道分隔的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5220624/

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