/******
*函数名称:strcut
*函数说明:通过左边界、右边界,从字符串中截取子字符串
*注意事项:会申请新的内存,需要手动释放
******/
void strcut(char *strSrc, char* str, char *leftStr, char *rightStr)
{
char *st1, *st2;
int result, i = ;
i=strlen(leftStr);
st1 = (char*) strstr(strSrc, leftStr);
if (st1 != NULL){
st1 += i;
st2 = (char*) strstr(st1,rightStr);
if (st2 != NULL){
result = st2 - st1;
*(st1 + result) = '\0';
}
}
if ((st1 == NULL) || (st2 == NULL))
lr_error_message("Error: No substring found for the specified boundary");
else
lr_save_string(lr_eval_string(st1),str);
}
void strcut(char *strSrc, char* str, char *leftStr, char *rightStr)
{
char *st1, *st2;
int result, i = ;
i=strlen(leftStr);
st1 = (char*) strstr(strSrc, leftStr);
if (st1 != NULL){
st1 += i;
st2 = (char*) strstr(st1,rightStr);
if (st2 != NULL){
result = st2 - st1;
*(st1 + result) = '\0';
}
}
if ((st1 == NULL) || (st2 == NULL))
lr_error_message("Error: No substring found for the specified boundary");
else
lr_save_string(lr_eval_string(st1),str);
} Action()
{
lr_save_string("{\"code\": \"00000000\", \"msg\": \"成功\", \"transId\": \"f6079c11ac9d463bb219acba8bc3448c\",\"data\": {\"randId\":\"e02a104a4a2f421b93bdb8f6d9daf7c0\"}}","allRes2"); strcut(lr_eval_string("{allRes2}"), "randId", "randId\":\"","\"}"); lr_output_message("randId:%s",lr_eval_string("{randId}")); return ;
}
void web_reg_save_param_custom(char *sourceStr, char* outpuStr, char *leftBdry, char *rightBdry){ char *st1, *st2; int result, i = 0; i=strlen(leftBdry); st1 = (char*) strstr(sourceStr, leftBdry); if (st1 != NULL){ st1 += i; st2 = (char*) strstr(st1, rightBdry); if (st2 != NULL){ result = st2 - st1; *(st1 + result) = '\0'; }
} if ((st1 == NULL) || (st2 == NULL)) lr_error_message("Error: No substring found for the specified boundary"); else lr_save_string(lr_eval_string(st1), outpuStr);
} Action()
{ lr_save_string("xyzToken3234344endKey,","test"); web_reg_save_param_custom(lr_eval_string("{test}"), "Outputtest", "Token","endKey"); lr_output_message("切割后的值=%s",lr_eval_string("{Outputtest}")); return 0;
}
深圳湖北籍软件测试群 275212937