为整个NSString生成NSRange的快捷方式? [英] Shortcut to generate an NSRange for entire length of NSString?

查看:99
本文介绍了为整个NSString生成NSRange的快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个简短的方法来说整个字符串而不是输入:

Is there a short way to say "entire string" rather than typing out:

NSMakeRange(0, myString.length)]

这类代码中最长的一部分是最不重要的,这似乎很愚蠢(因为我通常想在整个字符串中搜索/替换... ...

It seems silly that the longest part of this kind of code is the least important (because I usually want to search/replace within entire string)…

[myString replaceOccurrencesOfString:@"replace_me"
                          withString:replacementString
                             options:NSCaseInsensitiveSearch
                               range:NSMakeRange(0, myString.length)];


推荐答案

功能?分类方法?

- (NSRange)fullRange
{
    return (NSRange){0, [self length]};
}







[myString replaceOccurrencesOfString:@"replace_me"
                          withString:replacementString
                             options:NSCaseInsensitiveSearch
                               range:[myString fullRange]];

这篇关于为整个NSString生成NSRange的快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆