2012-03-06 28 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