使用姓名列表、字典、詹姆斯国王圣经等编写 rangeOfString 的最短方法是什么?
这很尴尬。我不想使用 coredata 或文本文件。我需要最短的方法来编写这段代码。
名字(“约翰”,“马太”,“托马斯”,“以撒”,“圣经”,“玛雅”,“2012”,更多名字)
这段代码花费了非常长的时间,浪费了太多的内存、下载时间和浪费空间。不推荐它。 10,000 行。
NSString *selectives = Name.text;
if ([selectives rangeOfString:@"John"].location != NSNotFound) {
//
}
if ([selectives rangeOfString:@"Matthew"].location != NSNotFound) {
//
}
第二。这段代码不起作用。我不知道我在这里做错了什么。我迷路了。我需要帮助!
NSString *string = Name.text;
NSString *NameMe = [NSString stringWithString:@"Jake", "miller", "thomas", "isaac"];
if([string rangeOfString:NameMe].location !=NSNotFound)
{
//
}
有更好的方法来写这个吗?你怎么写?我不擅长这个。
This is embarrassing. I don't want to use coredata or text file. I need shortest way to write this code.
names ("John", "Matthew", "thomas", "isaac", "bible", "Mayan", "2012", more names)
This code takes extremely long and wasting too much memory, download time, and waste of space. Not recommend it. 10,000 lines.
NSString *selectives = Name.text;
if ([selectives rangeOfString:@"John"].location != NSNotFound) {
//
}
if ([selectives rangeOfString:@"Matthew"].location != NSNotFound) {
//
}
Second. This code doesn't work. I don't what I'm doing wrong here. I'm lost. I need help!
NSString *string = Name.text;
NSString *NameMe = [NSString stringWithString:@"Jake", "miller", "thomas", "isaac"];
if([string rangeOfString:NameMe].location !=NSNotFound)
{
//
}
Is there a better way to write this? How do you write? I'm not good at this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在第一种情况下,您可以使用快速枚举来缩短代码。
在第二种情况下,这一行是错误的,
您没有传递正确格式的字符串。
@"Jake"
有效,其余部分则无效,因为它们位于@"..."
部分之外。In the first case you can use fast enumeration to shorten your code.
In the second case this line is wrong
You aren't passing in a properly formed string.
@"Jake"
is valid, the rest, because they are outside the@"..."
section are not.