我是iOS新手,需要一些帮助。 我正在做一个项目, 我需要在一个nsmutable数组中进行搜索,该数组包含数千个字符,其中包含不同和相同字符的组合,我需要搜索任何单词,如果找到单词,则应该是等距的集合。作为示例。假设我们有一组字符,如
ASDFGFDSRFCGFRDHUJKIHTGRDFESERTGADERWFSGETWGHWGDHWDG WDGOHARHDK
{HRSGDGHSVDFHDJJDKSKWREFGHUJDMSJDHJGDGAFGREFGSDSGDHHDHAHDJSGAFDH {1}} DHDHDGRGFDCVEDDSGDGDHDHNDHJDJSHGD。
如果我们从上面设置的字符中搜索“WORK”。然后它应该显示结果使上面的区域变暗。
答案 0 :(得分:0)
NSString *characterstring=@"ASDFGFDSRFCGFRDHUJKIHTGRDFESERTGADERWFSGETWGHWGDHWDGWDGOHARHDKHRSGDGHSVDFHDJJDKSKWREFGHUJDMSJDHJGDGAFGREFGSDSGDHHDHAHDJSGAFDHWRODRGKDHDHDGRGFDCVEDDSGDGDHDHNDHJDJSHGD";
NSString *cmpString=@"WORK";
int s;
int p;
for (int j=0; j<cmpString.length; j++) {
for (int i=0; i<characterstring.length; i++) {
char b=[characterstring characterAtIndex:i];
if(b ==[cmpString characterAtIndex:j])
{
s=i;
}
if (j<cmpString.length-1) {
if(b ==[cmpString characterAtIndex:j+1])
{
p=i;
if (i+(p-s)<characterstring.length-1) {
if([characterstring characterAtIndex:i+(p-s)] ==[cmpString characterAtIndex:j])
{
p=i;
NSLog(@"[characterstring characterAtIndex:i+(p-s)]=%c",[characterstring characterAtIndex:i+(p-s)]);
}
}
NSLog(@"====%c",b);
}
}
}
}