izan
izan

Reputation: 737

problems with NSString

I am sorry of the question, but i have searched but i have not found the solution. I have a textField, and i would like to add a caractère to the text of my textField. how to do this, please ?

if ( myConddition) {

otherTextField.text = myTextField.text ( a would like to add a caractér("1") to the first position ).

thanks for your answers

Upvotes: 0

Views: 165

Answers (4)

Jamie Chapman
Jamie Chapman

Reputation: 4239

Assuming you've created @property declarations...

[[self otherTextField] setText:[NSString stringWithFormat:@"1%@", [[self myTextField] text]]];

P.S. Eww at the use of dot notation by you boys and girls.

Upvotes: 0

Matthias Bauch
Matthias Bauch

Reputation: 90117

otherTextField.text = [@"1" stringByAppendingString:myTextField.text];

Upvotes: 0

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31730

Use below

NSMutableString* myString = [NSMutableString alloc] appendFormat:@"%@%@",@"1", myTextField.text]];
myTextField.text = myString;
[myString release];

Upvotes: 0

Ole Begemann
Ole Begemann

Reputation: 135578

otherTextField.text = [NSString stringWithFormat:@"1%@", myTextField.text];

Upvotes: 1

Related Questions