LPCSTR sFileName =F:\1\0\20081126\106\2042410.V3
我现在想取106这个值,注意:不能按位数来取,因为前边的数1 或者0有可能变为别的,只能按照‘\’来取,
同时,把取到的数据在转化为USHORT类型,谢谢
我现在想取106这个值,注意:不能按位数来取,因为前边的数1 或者0有可能变为别的,只能按照‘\’来取,
同时,把取到的数据在转化为USHORT类型,谢谢
解决方案 »
- Access中的数据表的命名中的-如何处理啊
- wtl 有appwizard 吗~
- 请教大侠:vc怎么浏览文件夹啊?(CFileDialog只能选择文件,不能选择文件夹啊。)
- 谁知道怎么用C语言来读取整个DVD碟片上的数据
- 向dll中传参数是引起malloc错误
- 在改变一个Frame大小时,如何限制它在达到一个最小值时便再也无法缩小? (Up有分)
- 如何检查用户是否安装了iis组件,如果没有时,自动打开控制面板控制其安装?
- 有关用CArray创建类型安全数组的问题
- 线程函数传地址问题问题
- GetCurrentThreadId()的问题
- MFC获取打开图片的文件名
- 如何解决对话框退出后主程序也退出的问题
char *pdest;
int result1 = 0, result2 = 0;;
for(int i = 0; i < 4; i++)
{
pdest = strchr( sFileName + result1, '\\' );
result1 = (int)(pdest - sFileName + 1);
}
pdest = strchr( sFileName + result1, '\\' );
result2 = (int)(pdest - sFileName + 1);
char *ch;
ch = new char[result2 - result1];
memcpy(ch, sFileName + result1, sizeof(ch));
ch[result2 - result1 - 1] = 0;
int j = atoi(ch);
delete []ch;
也可以用strtok来查找,不过它是非线程安全的,如果你不是用在多线程里面的要简单一些#include "stdafx.h"
#include <string.h>
int _tmain(int argc, _TCHAR* argv[])
{
char psData[]="F:\\1\\0\\20081126\\106\\2042410.V3";
char d[]="\\";
char *p;
p=strtok(psData,d);
while(p)
{
printf("%s\n",p);
p=strtok(NULL,d);
}
getchar();
return 0;
}结果是
F:
1
0
20081126
106
2042410.V3
#include "stdafx.h"
#include <string.h>
int _tmain(int argc, _TCHAR* argv[])
{
char psData[]="F:\\1\\0\\20081126\\106\\2042410.V3";
char d[]="\\";
char *p;
p=strtok(psData,d);
int iIndex=0;
while(p)
{
iIndex++;
if (iIndex==5)
{
printf("%s\n",p);
getchar();
return 0;
}
p=strtok(NULL,d);
}
getchar();
return 1;
}直接获得106