0

I have two UITextViews:

self.itemsTextView.text;
self.priceTextView.text;

I want to concatenate these two like so:

NSString *data = self.textView.text + self.itemsTextView.text;

I have tried using a colon, as suggested by this thread, but it doesn't work.

NSString *data = [self.textView.text : self.itemsTextView.text];
Community
  • 1
  • 1
bsiddiqui
  • 1,646
  • 4
  • 22
  • 35

3 Answers3

2

For concatenating you have several options :

Using stringWithFormat:

NSString *dataString =[NSString stringWithFormat:@"%@%@",self.textView.text, self.itemsTextView.text];

Using stringByAppendingString:

NSMutableString has appendString:

Anoop Vaidya
  • 45,475
  • 15
  • 105
  • 134
1

You may use

NSString * data = [NSString stringWithFormat:@"%@%@",self.textView.text,self.itemsTextView.text];
Shashank
  • 1,693
  • 1
  • 14
  • 20
0

There are so many ways to do this. In addition to the stringWithFormat: approaches of the other answers you can do (where a and b are other strings):

NSString *c = [a stringByAppendingString:b];

or

NSMutableString *c = [a mutableCopy];
[c appendString b];
rmaddy
  • 298,130
  • 40
  • 468
  • 517