仿写类似strstr()字符串匹配的二进制匹配方法FindBinaray()
2010-09-09 15:21
621 查看
在工作中遇到对于二进制数据的查找,类似于strstr()字符串匹配的函数,半天没有查到可以公用的API或是方法。
这不自己写一个来实现:
这不自己写一个来实现:
U8* FindBinary(const U8* pucSrc, int nsrcSize, const U8* pucFind, int nFindSize) { const U8 *pSrcPos = pucSrc; const U8 *pFindPos = pucFind; /* deliberately dumb algorithm */ while ( pSrcPos - pucSrc <= nsrcSize ) { pFindPos = pucFind; while ( (pSrcPos-pucSrc<=nsrcSize) && (pFindPos-pucFind<=nFindSize) ) { if (*pSrcPos != *pFindPos) break; pSrcPos++; pFindPos++; } if ( (pFindPos-pucFind) >= nFindSize ) return (U8 *)pSrcPos; //返回是查找匹配字符串的后一个字符指针 pSrcPos++; } return NULL; }
相关文章推荐
- php 类似正则获取字符串匹配内容的简单方法
- 【字符串匹配】KMP(implement strStr()), 正则匹配(Wildcard Matching),2-dim 动规(regular expression)
- sunday 字符串匹配算法的实现(支持二进制匹配)
- 几种字符串匹配的方法,以及一个讲解的很清晰的KMP匹配
- 字符串匹配算法——利用有限自动机进行匹配
- 九度OJ 1165:字符串匹配 (模式匹配)
- 字符串匹配Implement strStr()
- linux下通过字符模块实现类似ps命令的查看系统进程方法
- 字符串匹配算法strstr()
- Implement strStr():字符串匹配--》KMP
- LeetCode Implement strStr()(朴素的字符串匹配,RK算法,KMP算法)
- 【KMP&字符串匹配】Implement strStr()
- C++版字符串匹配算法之传统匹配算法加KMP字符串匹配算法
- JavaScript 字符串匹配 | JS 的正则用法 | 从后边匹配
- 寻找模式之旅(1)_字符串匹配 之 确定性方法
- 假设两个字符串中所含有的字符和个数都相同我们就叫这两个字符串匹配, 比如:abcda和adabc,由于出现的字符个数都是相同,只是顺序不同, 所以这两个字符串是匹配的。要求高效!
- C++_字符串匹配_忽略大小写_方法
- php匹配字符中链接地址的方法
- [字符串匹配、KMP]Implement strStr()
- js将二进制字符转换为十六进制方法