views:

94

answers:

2

Ik have the following strings in the .H file, and i want them to merge into one string at the end of the app when the have collected their data.

It wont work, why not and how must i do it correct so the data collected in these strings will be merged into one string ??

NSString *dataHML; 
NSString *dataHML2;
NSString *dataHML3;
NSString *dataHML4;
NSString *dataHML5;
NSString *dataHML6;
NSString *dataHMLtotal = *dataHML + *dataHML2 + *dataHML3 + *dataHML4 + *dataHML5 + *dataHML6;
+3  A: 
NSString *dataHtmlTotal = [NSString stringWithFormat:@"%@%@%@%@%@%@", dataHtml, dataHtml2, dataHtml3, dataHtml4,dataHtml5,dataHtml6];
Eimantas
Agreed. You can also use "[myString stringByAppendingString:myOtherString]" if you only need to combine two strings.
MrHen
no, sorry i need to merge 6 string outputs. So the above worked but i get the following error: NSString may not respond to '+dataHMLTotal:'
Ruiter
@Ruiter post your modified code.
Dave DeLong
A: 

Objective-C does not support operator overloading so + doesn't do what you want here. You can use: [NSString stringWithFormat:@"%@%@%@%@%@%@", dataHtml, dataHtml2, dataHtml3, dataHtml4, dataHtml5, dataHtml6];

instead.

Elfred
Thanks, that worked. But i'm getting a compiler error with this : NSString may not respond to '+dataHMLTotal:'
Ruiter