5

मैं स्ट्रिंग में एकाधिक स्ट्रिंग कैसे जोड़ूं? ऐसा करने का सबसे आसान तरीका क्या है? मैं हर बार जब मैं एक स्ट्रिंग के लिए कुछ जोड़ने के कोड की एक नई लाइन बनाने के लिए नहीं करना चाहती हैं, मैं ऐसा ही कुछ करना चाहते हैं:स्ट्रिंग में कई स्ट्रिंग्स जोड़ना

NSString *recipeTitle = [@"<h5>Recipe name: " stringByAppendingFormat:recipe.name, @"</h5>"]; 
    NSLog(@"%@", recipeTitle); 

    // This shows: <h5>Recipe name: myrecipe 
    // Where's the </h5> closing that header ? It will only show up with the next line of code 

    recipeTitle = [recipeTitle stringByAppendingFormat:@"</h5>"]; 

    //my problem is that will result in more than 1k lines of programming 

मैं जरूरी एक नई लाइन appending जोड़ने के लिए है हर बार संलग्न? क्या ऐसा करने के लिए एक तेज़/अधिक उत्पादक तरीका है?

मैं अपने बॉडीव्यू के साथ ईमेल बॉडी लिखने की कोशिश कर रहा हूं और इसके परिणामस्वरूप प्रोग्रामिंग लाइनों का एक बड़ा सेट होगा। क्या कोई भी मुझे कोई संकेत या कुछ भी एक huuuge स्ट्रिंग लिखने से बेहतर कुछ दे सकता है, तो मैं अपने ईमेल बॉडी को मेरे टेबलव्यू डेटा वाले टेबल के साथ पॉप्युलेट कर सकता हूं?

इसे और अधिक उत्पादक बनाने में कोई मदद की सराहना की जाती है। धन्यवाद ! कार्लोस फ़ारिनी।

// उस पर थोड़ा मुझे मिल गया काम करने के बाद:

-(IBAction)sendmail{ 
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init]; 
[composer setMailComposeDelegate:self]; 
NSString *recipeTitle = @"<h5>Recipe name: "; 
recipeTitle = [recipeTitle stringByAppendingFormat:recipe.name]; 
recipeTitle = [recipeTitle stringByAppendingFormat:@"</h5>"]; 

NSString *ingredientAmount = @""; 
NSString *ingredientAisle = @""; 
NSString *ingredientTitle = @""; 

NSString *tableFirstLine = @"<table width='90%' border='1'><tr><td>Ingredient</td><td>Amount</td><td>Aisle</td></tr>"; 
NSString *increments = @""; 
int i=0; 

for (i=0; i < [ingredients count]; i++) { 
    Ingredient *ingredient = [ingredients objectAtIndex:i]; 
    ingredientTitle = ingredient.name; 
    ingredientAmount = ingredient.amount; 
    ingredientAisle = ingredient.aisle; 

    increments = [increments stringByAppendingFormat:recipeTitle]; 
    increments = [tableFirstLine stringByAppendingFormat:@"<tr><td>"]; 
    increments = [increments stringByAppendingFormat:ingredientTitle]; 
    increments = [increments stringByAppendingFormat:@"</td><td>"]; 
    increments = [increments stringByAppendingFormat:ingredientAmount]; 
    increments = [increments stringByAppendingFormat:@"</td><td>"]; 
    increments = [increments stringByAppendingFormat:ingredientAisle]; 
    increments = [increments stringByAppendingFormat:@"</td></tr>"]; 
    if (i == ([ingredients count]-1)) { 
     //IF THIS IS THE LAST INGREDIENT, CLOSE THE TABLE 
     increments = [increments stringByAppendingFormat:@"</table>"]; 
    } 
} 

NSLog(@"CODE:: %@", increments); 

if ([MFMailComposeViewController canSendMail]) { 
    [composer setToRecipients:[NSArray arrayWithObjects:@"[email protected]", nil]]; 
    [composer setSubject:@"subject here"]; 
    [composer setMessageBody:increments isHTML:YES]; 
    [composer setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [self presentModalViewController:composer animated:YES]; 
    [composer release]; 
}else { 
    [composer release]; 
} 

}

लेकिन तब फिर से, यह तालिका में सिर्फ एक पंक्ति दिखा रहा है। मुझसे यहां क्या गलत हो रहा है ?

उत्तर

5

कैसे कुछ इस तरह के बारे में:

NSString *recipeTitle = [NSString stringWithFormat:@"<h5>Recipe name: %@ </h5>", recipe.name]; 
+0

मैं रख सकते हैं कई% @ और उसके बाद की तरह ... जाओ, recipe.name, recipe.preptime, recipe.included? मैं कोड की एक ही पंक्ति में तीन तारों को जोड़ रहा हूं। यह बुरा नहीं होगा ... – Farini

+1

हाँ, आप कर सकते हैं। आप तारों को उत्पन्न करने के अधिक तरीकों के लिए प्रलेखन की जांच भी कर सकते हैं। – Odrakir

+0

यह सही है। प्रबुद्धता के लिए धन्यवाद – Farini

संबंधित मुद्दे