LoadRunner – How to cut the string to the last x digits

In LoadRunner, getting the first n characters is an easy task by just using strncpy(). But what about when you want to get the number of characters from the last (right side)? So, there is no direct C or LoadRunner function that you can use to cut the string to the last x digits. For that purpose, we need to write a custom code. Refer to the below code; you can add this code in the LoadRunner script and get the desired output.

Action()
{
	char TIME[20];
	lr_save_timestamp("time",LAST);
	lr_output_message(lr_eval_string("{time}"));
	lr_param_sprintf("rev_time","%s",strrev(lr_eval_string("{time}")));
	strncpy(TIME,lr_eval_string("{rev_time}"),3);
	lr_param_sprintf("REV_TIME","%s",strrev(TIME));
	lr_output_message("%s",lr_eval_string("{REV_TIME}"));
	return 0;
}

Output:

Action.c(5): 1586522023175
Action.c(9): 175

You may be interested:


Leave a Comment