1.字符串替换,(删除也可以用空白替换)
方法:- stringByReplacingOccurrencesOfString:withString:options:range:
样例:
NSString * string=@"2016-05-05";
string=[string stringByReplacingOccurrencesOfString:@"-"withString:@"/"];
NSLog(@"replaceStr=%@",string);
输入结果如下
replaceStr=2016/05/05
2.字符串插入
方法
- (void)insertString:(NSString *)aString
atIndex:(NSUInteger)anIndex
样例:
+(NSString*)addSeparatorForPriceString:(NSString*)priceStr
{
NSString* price = @"3000000";
NSMutableString* tempStr = price.mutableCopy;
NSRange range = [price rangeOfString:@"."];
NSInteger index = 0;
if (range.length>0)
{
index = range.location;
}
else
{
index = price.length;
}
while ((index-3)>0)
{
index-=3;
[tempStr insertString:@"," atIndex:index];
}
tempStr = [tempStr stringByReplacingOccurrencesOfString:@"." withString:@","].mutableCopy;
return tempStr;
}
最后
以上就是不安棒棒糖最近收集整理的关于iOS字符串替换,字符插入,字符删除的全部内容,更多相关iOS字符串替换内容请搜索靠谱客的其他文章。
发表评论 取消回复