在LoadRunner中转换字符串大小写的C语言函数

 

封装ConvertToXXX函数:

//ConvertToUpper function

int ConvertToUpper(char * sInput, char * sNew)

{

 sInput = (char *)strupr(sInput);

 lr_save_string(sInput,sNew);

}

 

//ConvertToLower function

int ConvertToLower(char * sInput, char * sNew)

{

 sInput = (char *)strlwr(sInput);

 lr_save_string(sInput,sNew);

}

 

//ConvertToTitle function

int ConvertToTitle(char * sInput, char * sNew)

{

 int i = 0, s = 0, l = 0;

 char buf1[50];

 char buf2[2];

 char n;

 

 // Copy a single character into the address of [n]

 strncpy(&n,sInput+i,1);

 // Copy the single character into buf2

 sprintf(buf2,"%c",n);

 // Convert the contents of buf2 to uppercase

 strupr(buf2);

 // Overwrite the contents of buf1 with buf2

 strcpy(buf1,buf2);

 i++;

 while(i < strlen(sInput))

 {

  // Overwrite buf2 with one character

  strncpy(&n,sInput+i,1);

  sprintf(buf2,"%c",n);

  // If the previous character was a space then make the current character upper case

  if(s == 1){

   strupr(buf2);

   strcat(buf1,buf2);

   s = 0;

  }

  // Otherwise convert to lower case and concatenate the current character into the string buf1

  else{

   strlwr(buf2);

   strcat(buf1,buf2);

  }

  // If the current character is a space set the value of [s] to [1] so that the next character gets capitalised

  if(strcmp(" ",buf2)==0)

  {

   s = 1;

  }

  i++;

 }

 lr_save_string(buf1,sNew);

}

 

使用ConvertToXXX转换函数:

Action()

{

       lr_save_string("testing is believing","str");

       ConvertToUpper(lr_eval_string("{str}"),"UpperStr");

       lr_output_message(lr_eval_string("{UpperStr}"));

 

    ConvertToLower(lr_eval_string("{str}"),"LowerStr");

       lr_output_message(lr_eval_string("{LowerStr}"));

 

       ConvertToTitle(lr_eval_string("{str}"),"TitleStr");

       lr_output_message(lr_eval_string("{TitleStr}"));

 

       return 0;

}

 

输出:

Virtual User Script started at : 2010-01-30 17:53:13

Starting action vuser_init.

Web Turbo Replay of LoadRunner 9.50 SP1 for WINXP; WebReplay96 build 7045 (May 27 2009 14:28:58)       [MsgId: MMSG-27143]

Run Mode: HTML        [MsgId: MMSG-26000]

Run-Time Settings file: "D:/xlsoft/LR/MyTest/ConvertToXXXX//default.cfg"         [MsgId: MMSG-27141]

Ending action vuser_init.

Running Vuser...

Starting iteration 1.

Starting action Action.

Action.c(63): TESTING IS BELIEVING

Action.c(66): testing is believing

Action.c(69): Testing Is Believing

Ending action Action.

Ending iteration 1.

Ending Vuser...

Starting action vuser_end.

Ending action vuser_end.

Vuser Terminated.

 

参考:

http://www.bish.co.uk/index.php?option=com_content&view=article&id=68%3Aloadrunner-c-functions-to-convert-the-case-of-a-captured-string&catid=34%3Arecent&Itemid=1

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值