Nerver use NSString for string manipulation,Use NSMutableString.
NSMutableString is the subclass of NSString and used for that purpose.
From Apple Documentation:
The NSString class declares the programmatic interface for an object that manages immutable strings. (An immutable string is a text string that is defined when it is created and subsequently cannot be changed. NSString is implemented to represent an array of Unicode characters (in other words, a text string).
The mutable subclass of NSString is NSMutableString.
NSMutableString *word = [[NSMutableString alloc] initWithString:@"Hello"];
//Replace a character
NSString* word2 = [word stringByReplacingOccurrencesOfString:@"e" withString:@"a"];
[word release];
word = nil ;
word = [[NSMutableString alloc] initWithString:word2 ];
//Append a Character
[word appendString:@"a"];
There are more string manipulating function See Apple Documentation for NSMutableString
Edited:
you could first use rangeOfString to get the range of the string (in your case @"e").
- (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask
then check the NSRange object if it's valid then use the replaceCharactersInRange function on your NSMutableString to replace the set of characters with your string.
- (void)replaceCharactersInRange:(NSRange)aRange withString:(NSString *)aString