- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在给定文件中找到一个字符串(实际上该文件是 tar 文件(请注意此处),我在记事本++ 中打开该文件并从该打开的文件中随机取出一个字符串)并且我存储了完整的 tar缓冲区中的文件,现在我想在存储的缓冲区中找到我使用 strstr 函数复制的字符串的位置。
代码是这样的(绝对正确)-
char *compare= "_.png"; //suppose this is the copied string
//which is to be find out in buffer using strstr
char * StartPosition;
StartPosition = strstr (buffer,compare);
__int64 count=0;
MessageBox(m_hwndPreview,L"before the while loop",L"BTN WND6",MB_ICONINFORMATION);
while (StartPosition!=NULL)
{
MessageBox(m_hwndPreview,L"hurr inside the while loop",L"BTN WND6",MB_ICONINFORMATION);
MessageBoxA(m_hwndPreview,strerror(errno),"BTN WND4", MB_ICONINFORMATION);
count=StartPosition-buffer+1;
return 0;
}
假设我在记事本中有 tar 文件的内容,如下所示,从我复制存储在比较中的字符串的地方-
3_VehicleWithKinematicsAndAerodynamics_.000.png IHDR (here is some strange data which can't be copied and also there are lot of NULL but we have to find out the position of "_.png" so not so difficult in this case ).
问题是我的代码工作正常,直到我将数据存储在 .png 之前,然后我能够使用 strstr 找到它的位置问题是当我试图找出出现在
之后的字符串位置时`3_VehicleWithKinematicsAndAerodynamics_.000.png IHDR ...suppose here we have strange data (which is data block if we see the tar parser)...after this we have another file like..."3_VehicleWithKinematicsAndAerodynamics_.html"`
如果我想使用 strstr 找到这个“3_VehicleWithKinematicsAndAerodynamics_.html”,那么我无法找到它,因为它们之间有奇怪的数据。(因为我认为这些数据无法被编译器识别并且无法识别我无法访问位于奇怪数据之后的文件)为了更清楚地看到文件在 tar 文件中的位置如下-
3_VehicleWithKinematicsAndAerodynamics_.000.png IHDR ............(its data blocl-which is strange contents if you open in tar file)....3_VehicleWithKinematicsAndAerodynamics_.000.html
我必须使用 strstr 访问 .html 文件。为什么它不访问它??有任何想法吗 ?? *
请提供实现它的替代方法..我确信我尝试的方法不会起作用..
最佳答案
C 风格字符串是一些以零字符结尾的字符(NUL 字符 - 值零,而不是字符“0”)。这意味着 strstr
将在遇到这样的字节时立即停止。
一个相当合理的解决方案是简单地编写一个函数,根据二进制数据的长度而不是“终止符”来搜索二进制数据。
像这样(这仍然假定 str
是 C 风格的字符串):
char *find_str_in_data(const char *str, const char *data, int length)
{
int pos = 0;
int slen = strlen(str);
while(pos < length-slen)
{
int i = 0;
while(i < slen && str[i] = data[pos+i])
{
i++;
}
if (i == slen)
return data + pos;
}
return NULL;
}
关于c++ - strstr 无法以八进制格式搜索数据中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17882558/
谁能推荐一个好的成员(member)结构? 例如,用户支付了 1 个月的成员(member)费,从 2012 年 2 月 1 日到 2012 年 3 月 1 日结束。 何时何地检查用户是否仍是成员(m
我想在我的 JTextPane 中实现查找机制(如文本编辑器或 word)。我希望它有下一个/上一个选项(向上/向下箭头)并突出显示它找到的所有单词。有没有简单的方法可以做到这一点? 最佳答案 我不是
Android 上是否有任何机制和/或编程实践来执行一次性安装/更新脚本?这似乎是一个非常基本的问题,但谷歌搜索没有帮助。 假设我的应用程序使用了一个数据库,并且需要一个常量值表(例如国家名称、城市名
是否可以将 SimpleMembership 与 ASP.NET WebForms 一起使用? John Galloway 的文章似乎表明 WebForms“在 ASP.NET 成员资格之上实现 OA
我是一名优秀的程序员,十分优秀!