如何组合NSMutablearray中的字符串

时间:2012-03-06 12:58:09

标签: ios5 nsstring xcode4.2 string-concatenation

我正在试图弄清楚如何将来自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中以将其传递为电子邮件正文的最佳方法是什么?

提前致谢

-Paul

1 个答案:

答案 0 :(得分:0)

- (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;
}