I’m somehow using stringByReplacingCharactersInRange incorrectly, but I can’t understand how. My goal is to replace one character of an NSString with another. I do this many times but after two replacements it starts cutting from the end of the NSString, I don’t want this. Here is my code.
NSRange firstCharRange = NSMakeRange(mi, mi); // mi is an int, indicating the index of the replaced char
myword = [myword stringByReplacingCharactersInRange:firstCharRange withString:bb.titleLabel.text]; // myword is the string
Initially, myword is @”RRRRRRRR”, after replacing the first string it becomes
eRRRRRRR
then
egRRRRRR
then
eghRRRR // why did cut off the last character?
The second parameter of
NSMakeRange()is a length, not the end index. You probably want to just pass in1.