0

Possible Duplicate:
How do I concatenate strings in Objective-C?

Hello,

I am retrieving 10 separate strings from an XML parser. I want to append all the strings together. I checked for string concatenation in Obj-C and tried the below code, but it doesn't work as expected. Every time it overwrites with the new string.

 NSString *newstring; // Global variable

[newstring stringByAppendingString:newStrGotFromXML];

Could someone guide me to resolve this?

Thank you!

Community
  • 1
  • 1
Getsy
  • 4,887
  • 16
  • 78
  • 139
  • are you calling `NSString *newstring;` every time you want to append the string (I hope you're not cause I believe that may be the problem)? – Rasman Apr 23 '11 at 23:04

1 Answers1

1

the stringByAppendingString returns a new string by putting the two together, it doesn't modify either of the original strings. You probably want to use an NSMutableString. With that you can use the appendString method.

drewag
  • 93,393
  • 28
  • 139
  • 128