-2
A
回答
0
NSMutableString *a = [NSMutableString stringWithString:@"HOUSE" ];
NSString *b= @"MUSIC";
[a replaceCharactersInRange:NSMakeRange(0, 1) withString:[b substringWithRange:NSMakeRange(0, 1)]];
当你得到一个结果MOUSE ;-)
0
如果你正在寻找的方法是这样的:setCharacter:atIndex:
然后看下面的代码:
NSMutableString *string=[NSMutableString stringWithString:@"abcdefgh"];
[string setCharacter:'X' atIndex:0]; //Note X is character not string so "X" and its is primitive therefore even @ is not prefixed.
NSLog(@"%@",string);
这通过NSMutableString
的类别获得,其方法实施
@implementation NSMutableString (SetCharacterAtIndex)
- (void)setCharacter:(char)character atIndex:(NSUInteger)index;{
[self replaceCharactersInRange:NSMakeRange(index, 1) withString:[NSString stringWithFormat:@"%c",character]];
}
编辑:
具有上述方法之后,可以使用:
[一个characterAtIndex:0] = [B characterAtIndex:0];
[a setCharacter:[b characterAtIndex:0] atIndex:0];
相关问题
- 1. JavaScript将一个字符串的索引值分配给另一个索引值
- 2. 如何将字符串值分配给php数组的索引?
- 3. 索引字符串?
- 4. 字符串索引
- 5. 索引字符串
- 6. 将字符串插入给定索引的字符串
- 7. 作为字符的索引字符串
- 8. NSString的行索引和列索引的字符串索引
- 9. 在索引处分割字符串
- 10. python - 索引一个拆分字符串
- 11. 使用字符串索引
- 12. SOLR索引加字符
- 13. 子索引成字符串
- 14. 字符串索引OutOfBoundsException?
- 15. 字符串索引验证
- 16. postgresql索引字符串列
- 17. Win32 UTF-16字符索引
- 18. C++索引TCHAR字符串
- 19. 特殊字符索引
- 20. 索引,字符串,列表
- 21. 字符串索引的MySQL
- 22. 测试索引和字符
- 23. 字符串索引越界
- 24. PHP:字符串索引
- 25. 获取字符串索引
- 26. 索引Mysql字符串
- 27. 获取字符索引
- 28. 找到字符串索引
- 29. Lucene索引特殊字符
- 30. 替换字符串中给定索引处的字符?