ios NSMakeRange(i, 1) 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14412820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:55:28  来源:igfitidea点击:

What does NSMakeRange(i, 1) mean?

iosobjective-ccocoa-touch

提问by Xiaodong Gong

I just start to learn iOS.
What does "NSMakeRange(i, 1)" mean?

我刚开始学习iOS。
NSMakeRange(i, 1)”是什么意思?

for (int i = 0; i < [name length]; i++)
{
    NSRange range = NSMakeRange(i, 1);
    NSString *subString = [name substringWithRange:range];
    const char *cString = [subString UTF8String];
    if (strlen(cString) != 3)
    {
        return NO;
    }
}

Where is it used?

它在哪里使用?

回答by bdash

NSMakeRange(i, 1)creates a range with location iand length 1. See the documentation for NSMakeRangeand NSString substringWithRangefor further information and related functions.

NSMakeRange(i, 1)创建一个包含 locationi和 length的范围1。有关更多信息和相关功能,请参阅NSMakeRangeNSString substringWithRange的文档。

回答by zoul

Alt-click the function name in Xcode, you'll get a reference. The function creates a range that starts at iand has length of 1. In essence, you're picking individual characters from the string.

Alt- 在 Xcode 中单击函数名称,您将获得一个引用。该函数创建一个从 1 开始i且长度为 1的范围。本质上,您是从字符串中挑选单个字符。