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
What does NSMakeRange(i, 1) mean?
提问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 i
and length 1
. See the documentation for NSMakeRangeand NSString substringWithRangefor further information and related functions.
NSMakeRange(i, 1)
创建一个包含 locationi
和 length的范围1
。有关更多信息和相关功能,请参阅NSMakeRange和NSString substringWithRange的文档。
回答by zoul
Alt-click the function name in Xcode, you'll get a reference. The function creates a range that starts at i
and has length of 1. In essence, you're picking individual characters from the string.
Alt- 在 Xcode 中单击函数名称,您将获得一个引用。该函数创建一个从 1 开始i
且长度为 1的范围。本质上,您是从字符串中挑选单个字符。