2012-03-06 37 views
0

我想弄清楚如何将来自NSMutable阵列的数据合并为电子邮件正文的一部分。下面的代码产生以下的NSLog输出:如何组合来自NSMutable阵列的字符串

- (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被传递到是电子邮件的正文中最好的方法是什么?

在此先感谢

- 保罗

回答

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; 
} 
+0

真棒!感谢您的快速响应。 – 2012-03-06 18:12:51

+1

显示答案已被接受,然后未被接受。它没有工作吗? – Marco 2012-03-06 18:30:44