zoukankan      html  css  js  c++  java
  • LoadRunner 如何将英文的字符串转换成UTF-8格式的字符串?

    7.48  如何手动转换字符串编码

    1.问题提出

    如何将英文的字符串转换成UTF-8格式的字符串?

    2.问题解答

    可以使用lr_convert_string_encoding函数将字符串从一种编码手动转换为另一种编码(UTF-8、Unicode或本地计算机编码)。

    该函数的语法如下。

     

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

     

    该函数将结果字符串(包括其终止NULL)保存在第四个参数paramName中。如果成功,则返回0;失败,则返回−1。

    fromEncoding和toEncoding参数的格式如下。

     

    LR_ENC_SYSTEM_LOCALE       NULL

    LR_ENC_UTF8               "utf-8"

    LR_ENC_UNICODE            "ucs-2"

     

    在以下示例中,lr_convert_string_encoding将英文“Hello world”和字符串“我爱LR”由系统本地环境转换为Unicode,脚本代码如下。

     

    Action()

    {

        int rc = 0;

        rc= lr_convert_string_encoding("Hello world", LR_ENC_SYSTEM_LOCALE, LR_ENC_UNICODE,

    "strUnicode");

        if(rc < 0)

        {

            lr_output_message("转换"Hello world"失败!");

        }

        rc= lr_convert_string_encoding("我爱LR", LR_ENC_SYSTEM_LOCALE, LR_ENC_UNICODE,

    "strUnicode");

        if(rc < 0)

        {

            lr_output_message("转换"我爱LR"失败!");

        }

        return 0;

    }

     

    如果在“Run-time Settings”日志页启用了“Extended log”组的“Parameter substitution”复选框,则在执行日志中,输出窗口将显示以下信息。

     

    Running Vuser...

    Starting iteration 1.

    Starting action Action.

    Action.c(4): Notify: Saving Parameter "strUnicode = Hx00ex00lx00lx00ox00 x00wx00ox00rx00lx00dx00x00x00"

    Action.c(9): Notify: Saving Parameter "strUnicode = x11b1rLx00Rx00x00x00"

    Ending action Action.

    Ending iteration 1.

    Ending Vuser...

     

    从上面的脚本和代码中不难看出,应用lr_convert_string_encoding()函数可以将转换后的字符保存到strUnicode变量中。“Hx00ex00lx00lx00ox00x00wx00ox00rx00l x00dx00 x00x00”这段Unicode文本对应的是“Hello world”英文文本,而“x11b1rL x00Rx00x00x00”对应的是“我爱LR”字符串。

    LoadRunner 如何将英文的字符串转换成UTF-8格式的字符串?: PDF文档下载

  • 相关阅读:
    OD: Kernel Vulnerabilities
    newInstance()和new的区别
    原型模式
    工厂模式
    代理模式
    策略模式
    简单工厂模式
    C#操作符的重载
    旅行之舌尖上的中国
    模式和原则[转载]
  • 原文地址:https://www.cnblogs.com/tester2test/p/4104508.html
Copyright © 2011-2022 走看看