String Manipulation Functions
String Manipulation functions allow you to manipulate or
compare strings. These functions begin with the str prefix. Expand the
category to view a list of the available functions.
Click one of the following functions for more information:
Click one of the following functions for more information:
For instance we consider the function STRSTR and see how we use it.....
sample text :- 6172171084 (Service - RPC) Status: Success, Effective Immediately
If you want to capture the above text and try to see if any telephone number & success word is appearing in that phrase, then we use STRSTR function.
Using web_reg_save_param("Confirmation") - Pull that phrase into parameter called confirmation and then use that to validate if mobile number and success message are coming in the server response.
strstr
char *strstr( const char *string1, const char
*string2);Returns the first occurrence of one string in another.
string1
|
The string that is searched.
|
string2
|
The string that is searched for in
the first string.
|
strstr returns
the first occurrence of one string in another
This is how we do it..........
// If the success message is not displayed, fail the transaction and exit iteration
if (strstr(lr_eval_string("{Confirmation}"),"Success") < 1)
{
lr_error_message("***** Success Message not displayed ******");
lr_end_transaction("X_RPC_14_SubmitOrder", LR_FAIL);
lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
}
// Dynamic Validation for mobile number
if (strstr(lr_eval_string("{Confirmation}"), lr_eval_string("{mobile}")) == 0)
{
lr_error_message("***** Dynamic Validation Failed for mobile number*****");
lr_end_transaction("X_RPC_14_SubmitOrder", LR_FAIL);
lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
}
This is how we do it..........
// If the success message is not displayed, fail the transaction and exit iteration
if (strstr(lr_eval_string("{Confirmation}"),"Success") < 1)
{
lr_error_message("***** Success Message not displayed ******");
lr_end_transaction("X_RPC_14_SubmitOrder", LR_FAIL);
lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
}
// Dynamic Validation for mobile number
if (strstr(lr_eval_string("{Confirmation}"), lr_eval_string("{mobile}")) == 0)
{
lr_error_message("***** Dynamic Validation Failed for mobile number*****");
lr_end_transaction("X_RPC_14_SubmitOrder", LR_FAIL);
lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
}
Example
1
This example uses strstr to
search for the word "dog" in the string, str.
After strstr returns the address, position, the code then calculates the word's place in str by subtracting the address of the start of the string from position. This is the offset of the word "dog", in bytes.
After strstr returns the address, position, the code then calculates the word's place in str by subtracting the address of the start of the string from position. This is the offset of the word "dog", in bytes.
int offset;
char *
position;
char * str =
"The quick brown dog jumps over the lazy fox";
char *
search_str = "dog";
position =
(char *)strstr(str, search_str);
// strstr
has returned the address. Now calculate * the offset from the beginning of str
offset =
(int)(position - str + 1);
lr_output_message
("The string \"%s\" was found at position %d", search_str,
offset);
Output:
Action.c(14): The string "dog" was found at position 17
Action.c(14): The string "dog" was found at position 17
Example
2
The next example shows how strstr
can be used to parse file name suffixes. The code checks the equality of the
following two pointers:
- The pointer returned by strstr after searching for the substring is either null on failure, or the address of the first character of the file suffix on success. Adding 4 moves the pointer to the end of the string.
- The start of the string (path) plus its length, len. This is also the end of the string.
If these 2 pointers are equal than strstr
has found the file suffix. If not, strstr has returned null.
char * path
= "c:\\tmp\\xxx\\foo.ocx";
int len =
strlen(path), filetype;
// Check the
suffix of the file name to determine its type
if ((char
*)(strstr(path, ".dll") + 4) == (path + len))
filetype
= 1;
else if
((char *)(strstr(path, ".exe") + 4) == (path + len))
filetype
= 2;
else if
((char *)(strstr(path, ".tlb") + 4) == (path + len))
filetype
= 3;
else if
((char *)(strstr(path, ".ocx") + 4) == (path + len))
filetype
= 4;
else
filetype
= 5;
lr_output_message
("type = %d", filetype);
Output:
Action.c(18): type = 4
Action.c(18): type = 4
Thanks for sharing this and I hope this post may help us to know how to solve it.
ReplyDeleteLoadRunner Training in Chennai
Loadrunner Training
Loadrunner Training in Velachery
Loadrunner Training in Adyar
QTP Training in Chennai
UFT Training in Chennai
LoadRunner Training in Chennai
Loadrunner course in Chennai
Very useful post and I think it is rather easy to see from the other comments as well that this post is well written and useful. I bookmarked this blog a while ago because of the useful content and I am never being disappointed. Keep up the good work..
ReplyDeletesoftware testing company
QA Outsourcing Sevices
Performance testing Services
Nice & Informative Blog !
ReplyDeleteIn light of the prevailing situation, our team at Delta Customer Service offers a flat-price service for Delta.
Nice content, i am really very interested to read more about this topic, please keep posted on daily basis. If you face any issue or QuickBooks Error 3371 using QuickBooks, click here:QuickBooks Error 3371 For resolutions.
ReplyDeleteVery Nice article. It is very knowledgeable blog.Thank you for sharing with us. If you face any problem using QuickBooks, click here QuickBooks Customer Service phone number for technical help.
ReplyDeleteGreat Article you can useful provide information about quickbooks solution at
ReplyDeletequickbooks phone number
This comment has been removed by the author.
ReplyDeleteAfter Read Your Blog I m very impress. keep sharing it and you have also get more information about QuickBooks issue solution at quickbooks phone number
ReplyDeleteAmazing Blog !! Thanks For Sharing Valuable information .QuickBooks is a full package accounting software that fulfils all the needs of businesses. To get the quickest services for QuickBooks at
ReplyDeleteQuickBooks Customer Service.
Hey! What a wonderful blog. I loved your blog. QuickBooks is the best accounting software, however, it has lots of bugs like QuickBooks Error. To fix such issues, you can contact experts via QuickBooks Support Phone Number (602)325-1557.
ReplyDeleteHeyyy!!!
ReplyDeleteNice Blog.if you are looking for Quickooks Customer Service you can reach us at.+1 877-603-0806,IL.