views:

42

answers:

4

Hi.

I want to take two value from user i.e name and location and then want to concatenate them

into single string to produce output string

IBOutlet UITextField *txtName;
IBOutlet UITextField *txtLoc;

want to concatenate tem to produce below string.

Student Name is txtName and He is from txtLoc

Bescically thats my complete code.

NSString *message = [NSString stringWithFormat:@"Student Name is %@  from  %@ phone Number is%@ and he want to say%", txtName.text, txtLoc.text,txtPho.text,txtBody.text];



-(void) send:(id) sender {
    [self sendEmailTo:@"[email protected]" withSubject:@"Contact for Quran Focus from iphone Application" withBody:message];

Thats what i wana do. and em getting error

'txtName' undeclared here(not in a fuction)

'txtLoc' undeclared here(not in a fuction) 'txtPho' undeclared here(not in a fuction) 'txtBody' undeclared here(not in a fuction)

Though I have correctly declared all outlets;

+4  A: 
NSString *result = [NSString stringWithFormat:@"Student Name is %@ and He is from %@", txtName.text, txtLoc.text];
Claus Broch
only txtName.text, not just txtName
Vladimir
Yup, noticed that the second i posted.
Claus Broch
Thansk i have done that but em still getting this error... "'txtName'undeclared here(not in a function)"
Nauman.Khattak
The syntax for concatenating is correct. However you will also need to ensure that the txtName and txtLoc variables are known to the code. Make sure you #import the header files that defines them.
Claus Broch
+1  A: 
NSString *outputString=[NSString stringWithFormat:@"Student Name is %@ and he is from %@",txtName.text,txtLoc.text];
Henrik Erlandsson
A: 

Get the text string from each UITextField ([txtName text]) and use a stringByAppendingString method:

combinedString = [[txtName text] stringByAppendingString:[txtLoc text]]

Steven Noyes
+1  A: 

You need to put your message assignment line inside the send: function, just before the call to sendEmailTo:withSubject:withBody:.

Tommy Herbert
hhahah i make a blunder. thanks Tommy
Nauman.Khattak