【问题标题】:How to combine strings from NSMutable array如何组合来自 NSMutablearray 的字符串
【发布时间】:2012-03-06 12:58:08
【问题描述】:

我试图弄清楚如何将 NSMutable 数组中的数据组合成电子邮件正文的一部分。以下代码产生以下 NSLog 输出:

- (void)emailBody
{
    NSLog(@"Number of Songs: %@", profile.profileNumberOfSongs);
    NSLog(@"Profile Length:  %@", [self convertSecondstoMMSS:[profile.profileDuration intValue]]);

    for (ProfileItems *item in profileItemsNSMArray) 
    {
        NSLog(@"%@ %@ - %@ %@", item.profileItemsSongOrder, item.profileItemsMovementName, item.profileItemsArtist, item.profileItemsSong);
    }
}

NSLog 输出:

 Number of Songs: 9
 Profile Length:  40:07
 1 Seated Flat - Foo Fighters Home
 2 Seated Flat - Foo Fighters What If I Do?
 3 Standing Climb - Foo Fighters Tired Of You

将此数据存储到单个 NSString 以作为电子邮件正文传递的最佳方法是什么?

提前致谢

-保罗

【问题讨论】:

    标签: ios5 nsstring xcode4.2 string-concatenation


    【解决方案1】:
    - (NSString *)emailBody
    {
        NSMutableString *emailBodyString = [NSMutableString string];
        [emailBodyString appendFormat:@"Number of Songs: %@", profile.profileNumberOfSongs];
        [emailBodyString appendFormat:@"Profile Length: %@", [self convertSecondstoMMSS:[profile.profileDuration intValue]]];
    
        for (ProfileItems *item in profileItemsNSMArray) 
        {
            [emailBodyString appendFormat:@"%@ %@ - %@ %@", item.profileItemsSongOrder, item.profileItemsMovementName, item.profileItemsArtist, item.profileItemsSong];
        }
    
        return emailBodyString;
    }
    

    【讨论】:

    • 太棒了!感谢您的快速响应。
    • 显示答案被接受然后不被接受。没用吗?
    猜你喜欢
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 2018-03-25
    • 2020-03-06
    • 2018-02-13
    • 1970-01-01
    相关资源
    最近更新 更多