LoadRunner intercepts the string operation in the script using the LoadRunner winsockets protocol, encountering the following problem: In the results of the received query database I want to take the red part for the following selectrecv buf60 769 "\x01\x00\x00 \x01 "\BK" "\x00\x00\x02\x03" "def\tsystem_db\n" "tb_tsbinfo\n" "tb_tsbinfo\ftskguidebook\ftskguidebook\f?" "\x00" "\v" "\x00\x00\x00\x03" "" "\x00\x00\x00\x00" "A" "\x00\x00\x03\x03" "def\tsystem_db\n" "tb_tsbinfo\n" tb_ Tsbinfo "\x07" "work_id" "\x07" "work_id\f?" "\x00" "\v" "\x00\x00\x00\x03\x00\x00\x00\x00\x00" "G" "\x00\x00\x04\x03" "def\tsystem_db\n" "tb_tsbinfo\n" "tb_ tsbinfo\n "" worknum_id\n "" worknum_id\f? " "\x00" "\v" "\x00\x00\x00\x03\x00\x00\x00\x00\x00" "I" "\x00\x00\x05\x03" "def\tsystem_db" "\x10" "Tb_tskdetailinfo" " \x10 "" Tb_tskdetailinfo\bbatch ID "" \x02 "" id\f? " "\x00" "\v" "\x00\x00\x00\x03" "!" "\x00\x00\x00\x00" "Q" "\x00\x00\x06\x03" "def\tsystem_db" "\x10" "Tb_tskdetailinfo" "\x10" "tb_tskdetailinfo\ tbatchname\tbatchname\f! " "\x00" "," "\x01\x00\x00\xfd\x00\x00\x00\x00\x00" "C" "\x00\x00\x07\x03" "def\tsystem_db\n" "tb_tsbinfo\n" "tb_ Tsbinfo\bbloCk_id\bblock_id\f? " "\x00" "\v" "\x00\x00\x00\x03\x00\x00\x00\x00\x00" "I" "\x00\x00" "\b" "\x03" "def\tsystem_db\ftb_blockinfo\ftb_ blockinfo\tblockname\tblockname\f! " "\x00\x96\x00\x00\x00\xfd\x00\x00\x00\x00\x00" "G" "\x00\x00" "\ T" "\x03" "def\tsystem_db\ftb_blockinfo\ftb_ Blockinfo\bmodel_id\bmodel_id\f? " "\x00" "\v" "\x00\x00\x00\x03\x00\x00\x00\x00\x00\x05\x00\x00" "\ n" "\xfe\x00\x00" "\" "" \x00\x15\x00\x00 "" \v "" \x01 " "5" "\x01" "4" "\x01" "7" "\x01" "7" "\x04" "8227" "\x01" "6" "\x03" "Day" "\X01" "3" "\x15\x00\x00" "\f" "\x01" "5" "\x01 "4" "\x01" "7" "\x01" "7" "\x04" "8227" "\x01" "5" "\x03" "NEW" "\x01" "3" "\x18\x00\x00" "\ r" "\X01" "6" "\x01" "1" "\x "5" "\x01" "5" "\x04" "0502" "\x01" "4" "\x06" "Indent Board 瓧" "\X01" "2" "\x1a\x00\x00\x0e\x01" "9" "\x01" "1" "\x02" "One" "\x0 2 "One" "\x04" "1601" "\X01" "4" "\x06" "Indent Board 瓧" "\X01" "2" "\x1a\x00\x00\x0f\x01" "9" "\x01" "1" "\x02" "One" "\x02" " "" "1601" "\x01" "1" "\x06" "鍦 board from" "\X01" "2" "\x05\x00\x00\x10\xfe\x00\x00" "\" ""\x00 "Send Buf61" 2 "" \x00\x00\x00\x03 "" Select ' Blockno ' from ' tb_blockinfo ' where ' ID ' = 6 "write the associated statement: Lrs_save_searched_ String ("Socket3", NULL, "block_id", "lb/bin=\\x01", "rb/bin=\\x03", 8,0,-1), execution found the associated value is incorrect. Check that the results returned are: "\x01\x00\x00\x01" "\BK" "\x00\x00\x02\x03" "def\tsystem_db\n" "tb_tsbinfo\n" "Tb_tsbinfo\ftskguidebook \ftskguidebook\f? " "\x00" "\v" "\x00\x00\x00\x03" "" "\x00\x00\x00\x00" "A" "\x00\x00\x03\x03" "def\tsystem_db\n" "tb_tsbinfo\n" tb_ Tsbinfo\awork_id\awork_id\f? " "\x00" "\v" "\x00\x00\x00\x03\x00\x00\x00\x00\x00" "G" "\x00\x00\x04\x03" "def\tsystem_db\n" "tb_tsbinfo\n" "tb_ tsbinfo\n "" worknum_id\n "" worknum_id\f? " "\x00" "\v" "\x00\x00\x00\x03\x00\x00\x00\x00\x00" "I" "\x00\x00\x05\x03" "def\tsystem_db" "\x10" "Tb_tskdetailinfo" " \x10 "" Tb_tskdetailinfo\bbatch ID "" \x02 "" id\f? " "\x00" "\v" "\x00\x00\x00\x03" "!" "\x00\x00\x00\x00" "Q" "\x00\x00\x06\x03" "def\tsystem_db" "\x10" "Tb_tskdetailinfo" "\x10" "tb_tskdetailinfo\ tbatchname\tbatchname\f! " "\x00" "," "\x01\x00\x00\xfd\x00\x00\x00\x00\x00 "" C "" \x00\x00 "" \a "" \x03 "" def\tsystem_db\n "" tb_tsbinfo\n "" tb_tsbinfo\bblock_id\bblock_id\f? " "\x00" "\v" "\x00\x00\x00\x03\x00\x00\x00\x00\x00" "I" "\x00\x00" "\b" "\x03" "def\tsystem_db\ftb_blockinfo\ftb_ blockinfo\tblockname\tblockname\f! " "\x00\x96\x00\x00\x00\xfd\x00\x00\x00\x00\x00" "G" "\x00\x00" "\ T" "\x03" "def\tsystem_db\ftb_blockinfo\ftb_ Blockinfo\bmodel_id\bmodel_id\f? " "\x00" "\v" "\x00\x00\x00\x03\x00\x00\x00\x00\x00\x05\x00\x00" "\ n" "\xfe\x00\x00" "\" "" \x00\x16\x00\x00 "" \v "" \x01 " "2" "\x01" "3" "\x01" "2" "\x01" "2" "\x04" "8227" "\x02" "Ten" "\x03" "" "" "\X01" "4" "\x15\x00\x00" "\f" "\x01" "2" "\x0 1 "3" "\x01" "2" "\x01" "2" "\x04" "8227" "\x01" "9" "\x03" "One" "\x01" "4" "\x18\x00\x00" "\ r" "\X01" "3" "\x01" "1" "\ X01 "1" "\x01" "1" "\x04" "0001" "\x01" "1" "\x06" "鍦 board from" "\X01" "2" "\x18\x00\x00\x0e\x01" "3" "\x01" "1" "\x01" "1" 1 "1" "\x04" "0001" "\x01" "4" "\x06" "Indent Board 瓧" "\X01" "2" "\x05\x00\x00\x0f\xfe\x00\x00" "\" "\x00" The view is changed in \x04 and \x02 in "\x04" "8227" "\x02" "10" represent the number of digits of the following character, as one is \x01, and three is \x03. The table returns 8 columns, and I'm going to take the value of the sixth column in the first row. After viewing, change the associated statement to: Lrs_save_searched_string ("Socket3", NULL, "block_id", "Lb/bin=\\v", "rb/bin=\\r", 7,0,-1); The result is: \x012\ X013\x012\x012\x048227\x0210\x03two\x014\x15\x00\x00\f\x012\x013\x012\x012\x048227\x019\x03one\x014\x18\x00\ X00 I want to get the value after sixth "\". Write statement: Char *block;int i;int k;int len;//to take the length of the value char Block_str[100];char block_len[5]; Block=lr_eval_string ("<Block_ID>"); for (k=1;k<=6;) {i=i+1; if (block[i]== ' x ') k=k+1; }strncpy (block_len,block+i-1,4); Lrs_hex_string_to_int (Block_len,1,&len); strncpy (block_str,block+i+3,s); lr_ Output_message ("block=%s", block_str); Get the results you want. The collation script is as follows: Char *block;int i;int k;int len;//to take the length of the value char Block_str[100];char block_len[5];lrs_save_searched_string (" Socket3 ", NULL," block_id "," Lb/bin=\\v "," rb/bin=\\r ", 7,0,-1); Block=lr_eval_string ("<Block_ID>");//Get position of Sixth X for (k=1;k<=6;) {i=i+1; if (block[i]== ' x ') k=k+1; }strncpy (block_len,block+i-1,4);//intercept/x start four-bit Lrs_hex_strinG_to_int (Block_len,1,&len);//Convert to intstrncpy (block_str,block+i+3,s); Lr_output_message ("Block=%s", Block_str); In the process of writing down the script, it is necessary to write a function as follows://str, the string to be searched, N, the number of characters to be searched, the character Char *strn (char *str,int N,char c) {int nlen;//to intercept the length of the string. Decimal number char rstr[30]= "";//intercept the string char *retu=null;//to return the value char str_nlen[5]= "";//to intercept the length of the string, the character int len=0;//str the length int i=0;//the first few, Count int k=1;//number, count//Lr_output_message ("str=%s", str); Len=strlen (str);//Get the length of STR//Find the position of Nth X for (k=1;k<=n;) {i=i+1; if (STR[I]==C)//Determine if the character is C k=k+1; if (I+3>len) return 0;//find the end condition or not satisfied, return null} strncpy (str_nlen,str+i-1,4);//intercept \x0n, that is, the length of the value we want to take, string//Lr_output_ Message ("str_nlen=%s", Str_nlen); Lrs_hex_string_to_int (Str_nlen,1,&nlen);//convert Str_len to decimal number, put in Len//lr_output_message ("length to intercept =%d", nlen); strncpy (Rstr,str+i+3,nlen);//intercept the data we need//lr_output_message ("RSTR =%s", RSTR); RETU=RSTR; return Retu;} Say the strncpy function, there are two formats Char *strncpy (char *dest, char *src, int n); char *strncpy (Strtemp,str+n, m)--strtemp string variable, truncated string deposit --str charactersString variables,--n, int,--str+n, to intercept the string--m,int from the nth bit, representing the intercept m bit
LoadRunner Intercepting String Operations