xcode – 将多个字符串添加到字符串
发布时间:2020-12-14 17:53:20 所属栏目:百科 来源:网络整理
导读:如何在字符串中添加多个字符串? 这是最简单的方法吗? 如果我不想在每次向字符串添加内容时创建新的代码行,我想做类似的事情: NSString *recipeTitle = [@"h5Recipe name: " stringByAppendingFormat:recipe.name,@"/h5"]; NSLog(@"%@",recipeTitle); // T
如何在字符串中添加多个字符串?
这是最简单的方法吗? 如果我不想在每次向字符串添加内容时创建新的代码行,我想做类似的事情: 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 我是否必须每次添加附加附加的新行? 我正在尝试使用我的tableview编写电子邮件正文,这将导致一组庞大的编程行.我是否有人可以给我任何提示或任何比组成一个huuuge字符串更好的东西,以便我可以用包含我的tableview数据的表填充我的电子邮件正文? 任何有助于提高效率的帮助表示赞赏.谢谢 ! //在完成它之后我得到了一点: -(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:@"123@abc.com",nil]]; [composer setSubject:@"subject here"]; [composer setMessageBody:increments isHTML:YES]; [composer setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; [self presentModalViewController:composer animated:YES]; [composer release]; }else { [composer release]; } } 但话说回来,它只显示了表格中的一行.我在这做错了什么? 解决方法
这样的事情怎么样:
NSString *recipeTitle = [NSString stringWithFormat:@"<h5>Recipe name: %@ </h5>",recipe.name]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |