LoadRunner字符串处理 - 补齐字符串
有些时候需要在某个字符串的前面用0补齐,以便满足长度的格式要求。
在LoadRunner中可以封装出一个函数来处理这种问题:
/*
Function to pad a string to x characters adding the required character at the start of the string
(Note string length limited by length of the array)
Author: Steven Woodcock, Sopra Group
Inputs:
strCharToPad - The String that requires to be padded out i.e. "123456"
cParamName - The name of the parameter you want the end value to be saved to
iValLength - The length you want the string to be padded out to i.e. 9
cValueToAdd - The character you want to pad the string out with, must be a single character i.e. "0"
Outputs:
Creates a LoadRunner parameter of a name specified in the input 'cParamName'
*/
int lr_padstr(char* cCharToPad, char* cParamName, int iValLength, char* cValueToAdd){
char cTemp[1024] = "";
int iLoop = 0;
int iMainLoop = 0;
int iSubLoop = 0;
for(iMainLoop = 0; iMainLoop < iValLength; iMainLoop++){
if (iMainLoop == strlen(cCharToPad)) {
iLoop = iValLength - iMainLoop;
for (iSubLoop = 0; iSubLoop < iLoop; iSubLoop++) {
strcat(cTemp, cValueToAdd);
}
}
}
strcat(cTemp, cCharToPad);
lr_save_string(cTemp, cParamName);
}
lr_padstr可以在指定字符串前补齐指定长度的某个字符,然后把修改后的字符串存入LoadRunner参数中。把以上代码放到lr_padstr.h头文件中,在LoadRunner脚本中引用:
#include "lr_padstr.h"
Action()
{
// For the lr_padstr function
char * cShortValue = "123";
// For the sprintf function
char cPaddedValue[8] ="";
int iShortValue = 123;
int i;
// The lr_padstr function, written by Steven Woodcock can be used to pad with zeroes
lr_padstr(cShortValue,"pPaddedParameter",8,"0");
lr_output_message("Padded value is %s", lr_eval_string("{pPaddedParameter}"));
// The PadToX function can also be used to pad with other characters (e.g. x)
lr_padstr(cShortValue,"pPaddedParameter",8,"x");
lr_output_message("Padded value is %s", lr_eval_string("{pPaddedParameter}"));
return 0;
}
参考:
LoadRunner字符串处理 - 补齐字符串的更多相关文章
- C# 实现数字字符串左补齐0的两种方法
); MessageBox.Show(sss); return; 代码如上,自动补齐前面的0
- java中字符串左右补齐【转】
/** * 右左补齐 */ public static String padRight(String src, int len, char ch) { int diff = len - src.len ...
- sqlserver 2008 左补齐字符串
SQLServer:right函数 语法 Right(string, length) Right 函数的语法具有下面的命名参数: 部分 说明 string 必要参数.字符串表达式,从中最右边的 ...
- C#实现数字字符串左补齐0的方法
如下: ; , '); //0003 (推荐) s = string.Format("{0:d4}", n); //0003 再如: ; 方法1:Console.WriteLine ...
- C#实现数字字符串左补齐0的3种方法
int n = 3; string s = n.ToString().PadLeft(4, '0'); //0003 s = string.Format("{0:d4}", n); ...
- PHP数字字符串左侧补0、字符串填充和自动补齐的几种方法
一.数字补0. 如果要自动生成学号,自动生成某某编号,就像这样的形式“d0000009”.“d0000027”时,那么就会面临一个问题,怎么把左边用0补齐成这样8位数的编码呢?我想到了两种方法实现这个 ...
- StringUtils字符串工具类左侧补齐(leftPad)、右侧补齐(rightPad)、左右两侧补齐(center)工具方法
这里使用的是 org.apache.commons.lang.StringUtils;下面是StringUtils工具类中字符串左侧补齐的方法,示例如下: //左侧补齐 第一个参数:原始字符串,第二个 ...
- Delphi中字符串补齐方法
函数功能:当Str不满Len长度时,在Str前自动填充PadStr以补足长度,例子如下: Str:原字符串 Len:补多长 PadStr:用什么补齐,比如‘0’ function PadString( ...
- C 一个字符串有三段,第一段原样输出,第二段为要输出字符串的长度,第三段为依据第二段长度补齐第一段
C 一个字符串有三段,第一段原样输出.第二段为要输出字符串的长度,第三段为依据第二段长度补齐第一段 比如:输入abc 11 12.输出abc12121212 #include<stdio.h&g ...
随机推荐
- BZOJ 3282 Tree(动态树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3282 [题目大意] 0:后接两个整数(x,y),代表询问从x到y的路径上的点的权值的x ...
- 【动态规划/二维背包问题】mr355-三角形牧场
应该也是USACO的题目?同样没有找到具体出处. [题目大意] 和所有人一样,奶牛喜欢变化.它们正在设想新造型牧场.奶牛建筑师Hei想建造围有漂亮白色栅栏的三角形牧场.她拥有N(3≤N≤40)块木板, ...
- Java如何进行异常处理
关键字:throws.throw.try.catch.finally的用法 Java通过面向对象的方法进行异常处理,把各种不同的异常进行分类,并提供了良好的接口.在Java中,每个异常都是一个对象,它 ...
- TCP连接 断开
参考:http://blog.csdn.net/cyberhero/article/details/5827181 1.建立连接协议 (三次握手) (1)客户端发送一个带SYN标志的TCP ...
- Describe in brief Databases and SQL Server Databases Architecture.
Databases- A database is a structured collection of data.- Database can be thought as simple data fi ...
- mybatis查询日期时间数据得到long类型数据的问题
使用mybatis查询数据时,如果数据库存储的是timestamp.datetime.date.time等时间类型,而Java bean也使用的是date类型,mybatis会自动将date类型转换为 ...
- .Net 有关程序集查找与加载的一点反思
最近在做一款叫VICA产品,此产品采用了插件机制,插件在运行中加载,插件与插件之间存在依赖关系,所有的插件DLL为方便管理都放置在Plugins的文件夹下统一管理.这种处理方式不自觉的就让我想了解cl ...
- STSDB 一
STSdb 4.0 是一个开源的NoSQL 数据库和虚拟文件系统,支持实时索引,完全用c#开发的. 引擎原理基于WaterfallTree(瀑布树)数据结构搭建 以下内容基于stsdb4.dll(4. ...
- [Git] git revert ( revert commit 和 revert merge)
转载自:http://blog.csdn.net/qinjienj/article/details/7621887 我们难免会因为种种原因执行一些错误的commit / push,git提供了reve ...
- NAT和SNAT
在Kubernetes负载均衡的方案中遇到了SNAT的问题,查资料把SNAT和NAT的大意了解一下 详细信息可以直接访问 https://support.f5.com/kb/en-us/product ...