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,886
  • 5
  • 25
  • 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
  • 46,283
  • 15
  • 111
  • 140
1

You may use

NSString * data = [NSString stringWithFormat:@"%@%@",self.textView.text,self.itemsTextView.text];
Shashank
  • 1,743
  • 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
  • 314,917
  • 42
  • 532
  • 579