- 论坛徽章:
- 14
|
话太多了,你直接说形如“au_1_sel=作者,中英文作者,txt_1_special1==,txt_1_extension=xls”
是不是想分解成
"au_1_sel" _________"作者,中英文作者"
"txt_1_special1"_____"="
"txt_1_extension"____"xls"
?
不会正则,纯C的要不要?- #include <stdio.h>
- #include <string.h>
- int main()
- {
- //const char* str = "192.168.1.101,202.16.25.5 Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36 /A55/request/Search.aspx SEQ/ACK analysis,POST /A55/request/Search.a ×××××× %88%8,[Decoded Data] (31),action=undefined,NaviCode=*,PageName=ASP.brief_result_aspx,DbPrefix=CJFD,DbCatalog=某某某资料库,ConfigFile=CJFD.xml,db_opt=某某某资料库,db_value=某某某资料库,base_special1=%,magazine_special1=%,year_type=echar,au_1_sel=作者,中英文作者,au_1_sel2=机构,au_1_value2=首都师范大学,au_1_special1==,au_1_special2=%,txt_1_sel=主题,txt_1_value1=社会主义,txt_1_value2=经济,txt_1_relation=#CNKI_AND,txt_1_special1==,txt_1_extension=xls,txt_2_sel=主题,txt_2_value1=意识形态,txt_2_value2=政治,txt_2_logical=or,txt_2_relation=#CNKI_AND,txt_2_special1==,txt_2_extension=xls,his=0,__=Tue May 27 2014 23:41:14 GMT+0800 (中国标准时间)";
- const char* str = "SEQ/ACK [Decoded Data],a=b,c,d,e,f,g===h==i,j=,k=l";
- // find the head
- const char* p0;
- {
- p0 = strstr( str, "SEQ/ACK" );
- if( p0 )
- p0 = strstr( p0, "[Decoded Data]" );
- if( p0 )
- p0 = strchr( p0, ',' );
- if( p0 )
- ++p0;
- }
- while( p0 )
- {
- const char* p1 = strchr( p0, '=' );
- if( !p1 ) break;
- const char* p2 = strchr( p1+1, ',' );
- if( !p2 )
- {
- printf( "\"%.*s\"\t=\t\"%s\"\n", (int)(p1-p0), p0, p1+1 );
- break;
- }
- size_t idx;
- for( ; idx=strcspn(p2+1,",="), (p2+1)[idx]==','; p2=p2+1+idx );
- const char* p3 = p2+1+idx;
- if( !*p3 )
- {
- printf( "\"%.*s\"\t=\t\"%s\"\n", (int)(p1-p0), p0, p1+1 );
- break;
- }
- printf( "\"%.*s\"\t=\t\"%.*s\"\n", (int)(p1-p0), p0, (int)(p2-p1-1), p1+1 );
- p0 = p2+1;
- }
- return 0;
- }
复制代码 输出为
"a" = "b,c,d,e,f"
"g" = "==h==i"
"j" = ""
"k" = "l" |
|