最快的字符串查找???

jxf_yx 2005-03-26 12:58:59
想找最快的方法:
当前文件扩展名是否匹配(比如.gif) 下面字符串
.gif ¦.bmp ¦.zip ¦.jpg ¦.rm ¦.zip 等等。
...全文
239 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
hustwf 2005-03-30
  • 打赏
  • 举报
回复
对,就是KMP算法,一时忘了名字了,呵呵
在找长串的时候性能可以大大优化。
xiao_xiao_zi 2005-03-29
  • 打赏
  • 举报
回复
KMP字符串匹配算法啊,任何一本数据结构书都会讲的
long_xing 2005-03-28
  • 打赏
  • 举报
回复
数据结构中有一个最快匹配算法,不过strstr函数就一个很不错了
jxf_yx 2005-03-27
  • 打赏
  • 举报
回复
KMP算法?是什么
xiao_xiao_zi 2005-03-27
  • 打赏
  • 举报
回复
要想快的话就用KMP算法吧
IloveAzhu 2005-03-26
  • 打赏
  • 举报
回复
我觉得还是strstr比较快,内存开销也不大。
至于字符串链表我觉得不见得会快,本来这个就是比较成熟的东西,我觉得可以相信strstr
lake_wave 2005-03-26
  • 打赏
  • 举报
回复
摘自MSDN:

CString::Find
int Find( TCHAR ch ) const;

int Find( LPCTSTR lpszSub ) const;

int Find( TCHAR ch, int nStart ) const;

int Find( LPCTSTR pstr, int nStart ) const;

Return Value

The zero-based index of the first character in this CString object that matches the requested substring or characters; -1 if the substring or character is not found.

Parameters

ch

A single character to search for.

lpszSub

A substring to search for.

nStart

The index of the character in the string to begin the search with, or 0 to start from the beginning. The character at nStart is excluded from the search if nStart is not equal to 0.

pstr

A pointer to a string to search for.

Remarks

Searches this string for the first match of a substring. The function is overloaded to accept both single characters (similar to the run-time function strchr) and strings (similar to strstr).

Example

// First example demonstrating
// CString::Find ( TCHAR ch )
CString s( "abcdef" );
ASSERT( s.Find( 'c' ) == 2 );
ASSERT( s.Find( "de" ) == 3 );

// Second example demonstrating
// CString::Find( TCHAR ch, int nStart )
CString str("The stars are aligned");
int n = str.Find('e', 5);
ASSERT(n == 12);

poooorgun 2005-03-26
  • 打赏
  • 举报
回复
先用cstring 的find(".");再right()取出“.”后面的字符,再比较
xuzheng318 2005-03-26
  • 打赏
  • 举报
回复
CString的Find
hustwf 2005-03-26
  • 打赏
  • 举报
回复
看看数据结构C语言版,好像是清华出的,里面有个串查找的优话算法,只需要遍历一次就可以找到。
jxf_yx 2005-03-26
  • 打赏
  • 举报
回复
to: Featured(【我握着爱情的门票静静排队……】)
能否说下地址。

===
把 “.gif,.bmp,.zip,.jpg,.rm,.zip ”分隔了放在 字符串链表 中再查找比较速度和效率怎么样?
Featured 2005-03-26
  • 打赏
  • 举报
回复
最近论坛上另外一篇帖子里我帖了代码了

0011411 2005-03-26
  • 打赏
  • 举报
回复
???
oyljerry 2005-03-26
  • 打赏
  • 举报
回复
或CString的Find
fvan 2005-03-26
  • 打赏
  • 举报
回复
函数strstr的C源码,效率不低了啊

char * __cdecl strstr (
const char * str1,
const char * str2
)
{
char *cp = (char *) str1;
char *s1, *s2;

if ( !*str2 )
return((char *)str1);

while (*cp)
{
s1 = cp;
s2 = (char *) str2;

while ( *s1 && *s2 && !(*s1-*s2) )
s1++, s2++;

if (!*s2)
return(cp);

cp++;
}

return(NULL);

}
fvan 2005-03-26
  • 打赏
  • 举报
回复
如果直接检查某个字符串直接在另一个字符串中是否有匹配的直接用strstr()咯

#include<string.h>

if(!strstr(".gif,.bmp,.zip,.jpg,.rm,.zip",".gif")) //找不到就返回Null
return false;
jxf_yx 2005-03-26
  • 打赏
  • 举报
回复
上面格式错了:下面的
当前文件扩展名是否匹配(比如.gif) 下面字符串
.gif,.bmp,.zip,.jpg,.rm,.zip ... 等等。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧