Highlighted
Established Member..
Established Member..
186 views

How to replace Special Character in Transaction Names

Hi,

I have a scenario where according to the parameter values I need to change the transaction name and find the respective transaction response times.

I have done this thing in my script where according to the parameter values transaction names are changing, but the problem arises when it is going to close the transaction, because the parameter values are having some special characters and while it comes to close the transaction it is not able to understand that special characters and not closing the transaction and as a result transaction is getting failed.

Do you guys have any idea how to solve this problem or how to replace this special character with "_" as what LR understands.

Thanks,
Prasenjit
0 Likes
3 Replies
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: How to replace Special Character in Transaction Names

What is the special character you are talking about? Can you provide the screenshot of the same, if you can't interpret it here. based on ASCI values, you can convert it but requires more of c scripting with an add on script file or function. I suppose you can use strset() function. Refer Help file for more details on how to use it.


-Raj

Regards,
Raj

Like this Post? Click Kudos! to show appreciation.
Is your issue addressed? Click "ACCEPT AS SOLUTION" against the post which helped you the most.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: How to replace Special Character in Transaction Names

Prasenjit,

You can use this code that replaces characters in a string based on their ASCII codes. String "abcd@#$ 123^&*()" will be converted to: "abc____123_____". You can use it as a function passing pointer to the string as a function parameter.

char special_chars[]="abcd@#$ 123^&*()";
int i, c, len;

len = strlen(special_chars);
for (i=0; i c = special_chars[i];
if ((c < 48) || ((c >= 58) && (c <= 64)) || ((c >= 91) && (c <= 96)) || (c > 122)) {
special_chars[i] = '_';
}
}
lr_message("string=%s", special_chars);

GM
0 Likes
Highlighted
Established Member..
Established Member..

Re: How to replace Special Character in Transaction Names

Hi Gundu and GM,

Thanks for replying. I tried both the options but GM's one fit best for my case, but still getting one problem while using multiple OR in a if condition (screen shot attached). I have modified code a bit to match my case, please find it below.

int i,len,c;
char rname1[10];


sprintf( rname1, "%s", lr_eval_string("{pQ_SerchType}") );

lr_output_message(rname1);

len = strlen(rname1);

lr_output_message ("%d", len);
for (i=0; i{
if ((rname1[i] == '#') && (rname1[i] == ' ') || (rname1[i] == '(*)'))
{
rname1[i] = '_';
}
}
lr_output_message("string=%s", rname1);

Instead I found a different approach and it is working fine for my case.

Thanks a lot again.

Prasenjit
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.