vc 如何读取指定字符串所在行的内容 本帖最后由 a278401627 于 2013-01-28 02:37:46 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看来只有像一楼那样自己比较!使用这个// crt_strcmp.c#include <string.h>#include <stdio.h>#include <stdlib.h>char string1[] = "The quick brown dog jumps over the lazy fox";char string2[] = "The QUICK brown dog jumps over the lazy fox";int main( void ){ char tmp[20]; int result; // Case sensitive printf( "Compare strings:\n %s\n %s\n\n", string1, string2 ); result = strcmp( string1, string2 ); if( result > 0 ) strcpy_s( tmp, _countof(tmp), "greater than" ); else if( result < 0 ) strcpy_s( tmp, _countof (tmp), "less than" ); else strcpy_s( tmp, _countof (tmp), "equal to" ); printf( " strcmp: String 1 is %s string 2\n", tmp ); // Case insensitive (could use equivalent _stricmp) result = _stricmp( string1, string2 ); if( result > 0 ) strcpy_s( tmp, _countof (tmp), "greater than" ); else if( result < 0 ) strcpy_s( tmp, _countof (tmp), "less than" ); else strcpy_s( tmp, _countof (tmp), "equal to" ); printf( " _stricmp: String 1 is %s string 2\n", tmp );} CString.Find("$")//查找CString.Mid(pos1,pos2)//截取 如果数据很多的话,我建议你用fstream读取,我看每个数据都是用$8结尾的,用这个判断 ,当$8前面是你需要的数据时你就保存起来…… 把文件 全部 读入 buffer (注意 加个 0)char *pStartAt=strstr(buffer,“631”);char pEndAt=pStartAt;while((*pEndAt != 13 ) && (*pEndAt != 10 )) pEndAt++; CString str;int npos;str=6310A224488610$2$0.0.16$8;npos=str.Find('$');str.delete(0,npos+1);npos=str.Find('$');str=str.Left(npos);此时str的值为第一个$和第二个$之间的字符串。楼主可用while循环将整行以$分解成若干元素,直接取第二个元素。 nizhiqiang1128 这位朋友,用你的代码已经可以的把2提取出来了,谢谢不过现在的关键问题是怎么把6310A224488610$2$0.0.16$8;这行读出来 工具栏可以放在窗口边框上面吗???? 国庆 小散 心情比较灰暗 终于可以提问点轻松的问题啦 菜鸟求教:如何处理组合键消息 请问高人:怎么做一个类似于word中的保存功能??另存为又是怎样呢??谢谢!! 郁闷的CListView添加出来的行怎么会这样? 谁有最新的CSerialPort 类“?能发给我吗? 想要在对话框中的OnKeyDown()中处理四个方向箭头的事件,该怎么办? 关于DLL,简单,来者有分! 急,如何用c程序实现对一个可打印的文件(如*.doc,*.txt,*.bmp)进行自动打印?望各位高手不吝赐教 读XML数据生成XML文件 vc 如何读取指定字符串所在行的内容
使用这个// crt_strcmp.c#include <string.h>
#include <stdio.h>
#include <stdlib.h>char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";int main( void )
{
char tmp[20];
int result; // Case sensitive
printf( "Compare strings:\n %s\n %s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy_s( tmp, _countof(tmp), "greater than" );
else if( result < 0 )
strcpy_s( tmp, _countof (tmp), "less than" );
else
strcpy_s( tmp, _countof (tmp), "equal to" );
printf( " strcmp: String 1 is %s string 2\n", tmp ); // Case insensitive (could use equivalent _stricmp)
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy_s( tmp, _countof (tmp), "greater than" );
else if( result < 0 )
strcpy_s( tmp, _countof (tmp), "less than" );
else
strcpy_s( tmp, _countof (tmp), "equal to" );
printf( " _stricmp: String 1 is %s string 2\n", tmp );
}
CString.Mid(pos1,pos2)//截取
char *pStartAt=strstr(buffer,“631”);
char pEndAt=pStartAt;
while((*pEndAt != 13 ) && (*pEndAt != 10 )) pEndAt++;
CString str;
int npos;
str=6310A224488610$2$0.0.16$8;
npos=str.Find('$');
str.delete(0,npos+1);
npos=str.Find('$');
str=str.Left(npos);
此时str的值为第一个$和第二个$之间的字符串。
楼主可用while循环将整行以$分解成若干元素,直接取第二个元素。
这行读出来