problem while adding textfield text to NSMutablestring

567 views Asked by At

i need to add textfield text to NSMutable string when end of the textfield end.

for that i use the code

- (IBAction)my_textfield_editing {
    if ([my_textfield.text length]!=0) {
        [my_string appendString:my_textfield.text];
        NSLog(@"mystring %@",my_string);
    }
}

give this to textfield EditingDidEnd.

but i got some problem here.

for first editing it adds string as string1.

for second editing it adds string as string1string1,string2.

for third editing it adds string as string1string1,string2string1,string2,string3

i think it repeats with previous string.

i am trying placing my_string = NULL before adding it

if i use it always shows null.

how can i resolve it.

can any one help me.

Thank u in advance.


1

There are 1 answers

0
EmptyStack On BEST ANSWER

appendString: method won't work if you assign Null to a NSMutableString'. In order to make it work, you have to initialize it with some default string. In your case an empty string (ie., @""). For example, you have to initialize the mutable string like the following.

my_sms_string = [[NSMutableString alloc] initWithString:@""];