Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a character at a certain index in NSString

I'm looking for a way to replace a character at a certain index of a NSString.

For example: myString = @"******";

I want to replace the 3rd " * " with an "A", so that the string looks like this: myString = @"**A***";

How can I achieve this?

Thanks in advance

like image 709
niclas Avatar asked Jan 21 '12 12:01

niclas


1 Answers

Try with this:

NSString *str = @"*******";
str = [str stringByReplacingCharactersInRange:NSMakeRange(3, 1) withString:@"A"];
NSLog(@"%@",str);
like image 165
aViNaSh Avatar answered Sep 23 '22 21:09

aViNaSh