append - Objective-C difference in concatentation methods -


clarification question here. attempting concatenate 2 strings using stringbyappendingstring method:

nsstring *datastring = @","; nsinteger = 0; nsstring *cyclecountstring = @""; (i = 0; i<[[self cyclelist] count]; i++) {      cyclecountstring = [nsstring stringwithformat:@"cycle#%d,",i];     [datastring stringbyappendingstring:cyclecountstring]; } nslog(@"datastring is: %@",datastring); 

however, nslog outputing "," if cyclecountstring not being appended datastring.

after reading:http://stackoverflow.com/questions/510269/how-do-i-concatenate-strings-in-objective-c , able fix issue instead doing stringwithfromat:

nsstring *datastring = @","; nsinteger = 0; nsstring *cyclecountstring = @""; (i = 0; i<[[self cyclelist] count]; i++) {      cyclecountstring = [nsstring stringwithformat:@"cycle#%d,",i];     datastring = [nsstring stringwithformat:@"%@%@",datastring,cyclecountstring];   } nslog(@"datastring is: %@",datastring); 

any idea why previous method wasn't working? stringbyappendingstring not work way think does?

thanks!

you're never updating value of datastring.

datastring = [datastring stringbyappendingstring: cyclecountstring]; 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -