您的位置:首页 > 其它

LoadRunner函数详解之lr_convert_string_encoding

2015-07-24 13:07 316 查看
定义:字符编码System locale, Unicode, UTF-8之间的相互转换,转换结果保存在“结果字符串”中,该“结果字符串”包含NULL–字符串结束符

函数形式:

lr_convert_string_encoding(const char *sourceString, const char *fromEncoding, const char *toEncoding, const char *paramName);

参数详解:



基本信息:

结果字符串包含的“可打印字符”能在VuGen和日志信息中以实际字符显示,“不可打印字符”以16进制显示,例如:

rc = lr_convert_string_encoding("A", NULL, LR_ENC_UTF8, "stringInUnicode");
结果字符串显示为A\x00, 而不是\x41\x00, 因为A是可打印字符


fromEncoding 和 toEncoding可能的取值:



示例1:使用 lr_convert_string_encoding 将字符串”Hello world”从System locale编码转换为Unicode编码。

Action()
{
int rc = 0;
unsigned long converted_buffer_size_unicode = 0;
char *converted_buffer_unicode = NULL;
rc = lr_convert_string_encoding("Hello world",
LR_ENC_SYSTEM_LOCALE,
LR_ENC_UNICODE,
"stringInUnicode");
if(rc < 0)
{
lr_output_message("字符编码转换失败");
}
return 0;
}

结果输出:
Starting action Action.
Action.c(7): Notify: Saving Parameter "stringInUnicode = H\x00e\x00l\x00l\x00o\x00 \x00w\x00o\x00r\x00l\x00d\x00\x00\x00"
Ending action Action.


注:目前使用最广泛的西文字符集及其编码是 ascii 字符集和 ASCII 码( ASCII 是 American Standard Code for Information Interchange 的缩写),它同时也被国际标准化组织( International Organization for Standardization, iso )批准为国际标准。 基本的 ASCII 字符集共有 128 个字符,其中有 96 个可打印字符,包括常用的字母、数字、标点符号等,另外还有 32 个控制字符。标准 ASCII 码使用 7 个二进位对字符进行编码,对应的 ISO 标准为 ISO646 标准
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: