Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Was this something new to you?


  • Total voters
    2
  • Poll closed .

vidyareef

macrumors newbie
Original poster
Jan 11, 2009
8
0
Hello!


to concatenate the string with a wriiten text
(here Hello world )
and a value existing in the code
we usually use this
myLabel.text= [NSString stringWithFormat:mad:"Hello world ", myString];

But now if i have two values existing in the code e.g. inforesult and myString how can i concatenate them together ?

i tried
myLabel.text= [NSString stringWithFormat: inforesult, myString];

but it doesn't work. Returns me only the inforesult value displayed.

How can i solve this?
 

vidyareef

macrumors newbie
Original poster
Jan 11, 2009
8
0
while searching i also got
NSString *string1= Inforesultat;
NSString *string2 = myString;
string1 = [string1 stringByAppendingString:string2];


I wonder what is the difference and which one is better to use?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
stringByAppendingString is probably a little more efficient. stringWithFormat is a general method that can do a lot of things. Obviously it has to parse the format string and then apply the parameters to the parsed format. stringByAppendingString does one thing only so can be simpler and faster.

Having said that it probably will make little difference in most cases and my analysis is based on my assumptions and not on knowledge of the implementation.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.