.在globals.h 中定义一个函数ReplaceStr,实现字符串的替换: int ReplaceStr(char* sSrc, char* sMatchStr, char* sReplaceStr)
{
int StringLen;
char caNewString[];
char* findPos;
merc_timer_handle_t timer_ReplaceStr = lr_start_timer(); lr_debug_message(LR_MSG_CLASS_EXTENDED_LOG ,"Notify:Function 'ReplaceStr' started.");
findPos =(char *)strstr(sSrc, sMatchStr);
if( (!findPos) || (!sMatchStr) ){
lr_debug_message(LR_MSG_CLASS_EXTENDED_LOG ,"Notify:Function 'ReplaceStr' ended with error!");
return -;
} while( findPos)
{
memset(caNewString, , sizeof(caNewString));
StringLen = findPos - sSrc;
strncpy(caNewString, sSrc, StringLen);
strcat(caNewString, sReplaceStr);
strcat(caNewString, findPos + strlen(sMatchStr));
strcpy(sSrc, caNewString); findPos =(char *)strstr(sSrc, sMatchStr);
}
lr_debug_message(LR_MSG_CLASS_EXTENDED_LOG,"Result:%s",sSrc);
free(findPos);
lr_debug_message(LR_MSG_CLASS_EXTENDED_LOG ,"Notify:Function 'ReplaceStr' ended (Duration: %lf)",
lr_end_timer(timer_ReplaceStr));
return ;
} .在init/Action/end 中调用: char strView[]; web_reg_save_param("viewState5",
"LB=\"javax.faces.ViewState\" value=\"",
"RB=\"",
LAST); sprintf(strView,lr_eval_string("{viewState5}")); ReplaceStr(strView,"+","%2B");
ReplaceStr(strView,"/","%2F");
ReplaceStr(strView,"=","%2D"); lr_save_string(lr_eval_string(strView), "viewState6"); memset(strView,,sizeof(strView));