bsiddiqui
bsiddiqui

Reputation: 1926

How to concatenate TextView.text

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];

Upvotes: 0

Views: 493

Answers (3)

rmaddy
rmaddy

Reputation: 318804

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];

Upvotes: 0

Shashank
Shashank

Reputation: 1753

You may use

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

Upvotes: 1

Anoop Vaidya
Anoop Vaidya

Reputation: 46543

For concatenating you have several options :

Using stringWithFormat:

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

Using stringByAppendingString:

NSMutableString has appendString:

Upvotes: 2

Related Questions