Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i add to a mutable string in objective c?

Without getting into to much detail about the actual program,I want to take an existing string and add more characters(or strings) to it. If this were done in java it would be like this

String x= "hello"

x= x + "world";

I currently have my string trying to do that like this. My string declared is called _whatiscorrect, it is an empty string right now and in this example i want to take the existing string and add an "o" to it.

_whatiscorrect = [_whatiscorrect stringByAppendingString:@"o"]; // place an o in the string

How do i do this?

like image 473
Chris Braswell Avatar asked Mar 02 '26 22:03

Chris Braswell


1 Answers

You have the right idea. Just do this:

NSMutableString * _whatiscorrect = [[NSMutableString alloc] initWithString: @".."];
[_whatiscorrect appendString:@"o"];
like image 166
soundsmitten Avatar answered Mar 04 '26 21:03

soundsmitten



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!