Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append int value to string?

NSMutableString  *selectDay=@"Wed 14 May";
[selectDay stringByAppendingFormat:@"%i", yearNumber];
NSLog(@"%@",selectDay);

I will tried this one.But it can't append the yearNumber to that String please help me.YearNumber contain 2011.

like image 655
venkat Avatar asked Mar 02 '26 03:03

venkat


1 Answers

stringByAppendingFormat: returns the new string, it does not modify the receiver string. That's why you are getting no change. Try this:

NSMutableString  *selectDay=@"Wed 14 May";
NSString *newString = [selectDay stringByAppendingFormat:@"%i", yearNumber];
NSLog(@"%@", newString);

Or this:

NSMutableString  *selectDay=@"Wed 14 May";
NSString *newString = [NSString stringWithFormat:@"%@%i", selectDay, yearNumber];
NSLog(@"%@", newString);

EDIT: Actually you don't need mutable string for this. selectDay should be a normal NSString.

NSString  *selectDay=@"Wed 14 May";
like image 194
taskinoor Avatar answered Mar 04 '26 15:03

taskinoor



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!