NSMutableAttributedString 文字处理 。。。
来源:互联网 发布:住宅验收规范数据 编辑:程序博客网 时间:2024/04/27 00:16
#pragma mark - 文本处理
+ (NSMutableAttributedString *)attributeStringWith:(NSMutableAttributedString *)attributeString andAttributes:(NSDictionary *)attribute
{
NSMutableArray *rangeArray = [NSMutableArray array];
for(NSInteger i=0; i < attributeString.length; i++)
{
NSRange range = NSMakeRange(i, 1);
NSString *str = [attributeString.string substringWithRange:range];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",@"^[0-9]"];
if([predicate evaluateWithObject:str])
{
[rangeArray addObject:[NSValue valueWithRange:range]];
}
}
// [rangeArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// NSRange range = [(NSValue *)obj rangeValue];
// [attributeString addAttributes:attribute range:range];
// }];
[rangeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSRange range = [(NSValue *)obj rangeValue];
[attributeString addAttributes:attribute range:range];
}];
return attributeString;
}
+ (NSMutableAttributedString *)attributeStringWith:(NSMutableAttributedString *)attributeString andAttributes:(NSDictionary *)attribute
{
NSMutableArray *rangeArray = [NSMutableArray array];
for(NSInteger i=0; i < attributeString.length; i++)
{
NSRange range = NSMakeRange(i, 1);
NSString *str = [attributeString.string substringWithRange:range];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",@"^[0-9]"];
if([predicate evaluateWithObject:str])
{
[rangeArray addObject:[NSValue valueWithRange:range]];
}
}
// [rangeArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// NSRange range = [(NSValue *)obj rangeValue];
// [attributeString addAttributes:attribute range:range];
// }];
[rangeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSRange range = [(NSValue *)obj rangeValue];
[attributeString addAttributes:attribute range:range];
}];
return attributeString;
}
0 0
- NSMutableAttributedString 文字处理 。。。
- 文字处理
- 文字处理
- 文字处理
- 文字处理
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- vi文字处理
- Oracle job及导入导出数据库
- ios 本地推送
- http直接访问含有中文的ulr失败
- 动画特效十八:粘性动画2
- ZOJ 3631超大背包问题(DFS || 折半搜索)
- NSMutableAttributedString 文字处理 。。。
- Linux 平台 Oracle 单实例 从10.2.0.1 升级到10.2.0.5.4 步骤
- 【BZOJ4311】向量
- Swift中类的操作
- 虚拟机联网问题(原理及解决方案)
- inflate方法
- 正则表达式
- OC中实例方法和类方法的区别
- Git详解之二:Git基础