Saturday, 15 March 2014

objective c - How do I combine strings? -



objective c - How do I combine strings? -

this question has reply here:

shortcuts in objective-c concatenate nsstrings 28 answers combining 2 strings [duplicate] 2 answers

i'm trying combine strings have collected text fields , combine them in tweetsheet.

i have [tweetsheet setinitialtext: namestring1]; , when seek add together multiple ones together... [tweetsheet setinitialtext: namestring1, namestring2, otherstringstuff]; gives me error saying have "too many arguments method call, expected 1, have 6"

i'm used android development can do: namestring1 + " :" + namestring2 + otherstringstuff

how add together multiple strings , utilize quotes add together space between?

you need create final string before sending ot tweet sheet:

option 1:

nsstring *final = [[nsstring alloc] initwithformat:@"%@%@%@", str1, str2, str3]; [tweetsheet setinitialtext: final];

the dowside this, deals predetermined number of strings.

option 2:

nsarray *strings = ... // build array strings want. nsmutablestring *final = [[nsmutablestring alloc] initwithstring:@""]; // loop assuming "strings" contains nsstrings or 1 of subclasses // might want validation ( nsstring *str in strings ) { [final appendstring:str]; } [tweesheet setinitialstring:final];

with option, have create sure strings going array formatted first, since, can see, there no formatting done in loop.

objective-c string nsstring

No comments:

Post a Comment