推荐优先使用以下方法
lr_save_string("kA_Vv4Y9xR7rqnbVs0tQXDEJ0MSbWaLAqcczHfDNg6X18x8wNFk9%2FM%3D","encodedStr1");
web_convert_param("encodedStr1", "SourceEncoding=HTML", "TargetEncoding=URL", LAST );
其次
void encodeString(const char * original,char * output_param_name)
{
int counter, out_counter;
char * encodedStr = (char *)malloc((strlen(original)*2)+1); // will make sure there is enough room for new string
char buffer[4]; // buffer to hold hexidecimal version of the character
for(counter=0,out_counter=0;counter<(int)strlen(original);counter++,out_counter++)
{
if(isalnum(original[counter]))
encodedStr[out_counter]=original[counter];
else
{
sprintf(buffer, "%%%X", original[counter]); //prints %Hex_Value (%20) of the original character
//grabs first three characters of the buffer which is the hex value we want
encodedStr[out_counter++] = buffer[0];
encodedStr[out_counter++] = buffer[1];
encodedStr[out_counter] = buffer[2];
}
}
encodedStr[out_counter]='/0'; //end the string
lr_save_string(encodedStr,output_param_name); //save string into parameter
free(encodedStr); //free memory
}
本文介绍了如何使用特定函数进行编码转换和字符串操作,包括从HTML编码到URL编码的转换,以及自定义字符串编码方法。
1846

被折叠的 条评论
为什么被折叠?



