NSMutableString * string = [[NSMutableString alloc] initWithString:@"hello134hello"];
NSLog(@"%@",[self string:[string mutableCopy] start:2 end:5]);
NSLog(@"%@",[self string:[string mutableCopy] start:1 end:3]);
NSLog(@"%@",[self string:[string mutableCopy] start:1 end:2]);
/// 替换字符,将字符串中的部分数据换成另一个
/// @param string 要修改的字符串
/// @param num 替换的起始位置
/// @param end 替换的长度
-(NSString *)string:(NSMutableString *)string start:(NSInteger)num end:(NSInteger)end{
NSRange range = NSMakeRange(num, end);
NSString * str2 = @"";
for (int i = 0; i < end; i++) {
str2 = [NSString stringWithFormat:@"%@*",str2];
}
[string replaceCharactersInRange:range withString:str2];
return string;
}
网友评论