Loadrunner - concatenation using lr_save_string - concatenation

Is it possible to concatenate using lr_save_string?
sortoption,next and basket, bookIDs_array are all correctly assigned values.
Code
lr_save_string(lr_eval_string("sortoption={sortoption}&next={next}&basket={basket}"), "BodyString");
for (i=1; i<=lr_paramarr_len("BookIDS_array"); i++) {
lr_save_string(lr_paramarr_idx("BookIDS_array", i), "BookID");
lr_save_string(lr_eval_string("{BodyString}&bookId%5B%5D%3D{BookID}"), "BodyString");
}
lr_output_message("Value: %s", lr_eval_string("{BodyString}"));
However the above seems to just assign the below to BodyString
sortoption={sortoption}&next={next}&basket={basket}

You may want to consider this other thread for a concatenation example in LoadRunner
How to change input soap request as per test data in loadrunner?

I took a look at the XML link and it's very similar to what I wanted to do, but I had some json to update if there was a value. My approach to the issue below:
//Define the object to store.
char ifPhoneThenAdd[100];
...
...
...
//Capture the full part of the address information of the first entry including city, phone, etc. - In my scenario, all I need is the first one from the json response..
web_reg_save_param_json("ParamName=AddressData","QueryString=$.Addresses","SelectAll=No",SEARCH_FILTERS,"Scope=Body",LAST);
...
...
...
web_rest("......",
"URL={App_URL}/details/{userID}",
"Method=GET",
"Snapshot=t999990.inf",
LAST);
...
...
...
//Some explanation of the json output:
//A sample of the json output would look something like this (from the output tab):
//Saving Parameter "AddressData" = [{"Id":"xxxxxxxxxxx","city":"Calgary","street":"123 Santas Workshop","postalCode":"H0H 0H0","country":"CA","region":"AB","email":"baba#oriley.com","phone":"403xxxxxxx"}]"
//Without the phone, it would be:
//[{"Id":"xxxxxxxxxxx","city":"Calgary","street":"123 Santas Workshop","postalCode":"H0H 0H0","country":"CA","region":"AB","email":"baba#oriley.com"}]"
//This part changes the body in case there is a phone number and does not include phone number if there is none in the reply.
sprintf(ifPhoneThenAdd,"");
if (strstr(lr_eval_string("{AddressData}"), "\"phone\"") != NULL)
{
lr_eval_json("Buffer={AddressData}", "JsonObject=json_obj", LAST);
lr_json_get_values("JsonObject=json_obj", "ValueParam=AddressWithPhoneNumber", "QueryString=$..phone", "SelectAll=No", LAST);
sprintf(ifPhoneThenAdd,"%s%s%s",",\r\n\"phoneNumber\":\"",lr_eval_string("{AddressWithPhoneNumber}"),"\"");
}
else
{
//Doesn't make the script fail, but will send an error message.
lr_error_message("No phone number for ID: %s", lr_eval_string("{userID}"));
}
lr_save_string(ifPhoneThenAdd, "ifPhoneThenAddString");
//If there is no phone, then the string ifPhoneThenAddString will be empty and nothing but the empty string will be added to the json output.
//If there is a phone, then the body will get appended with the right json output with the phone number.
...
...
...
web_rest("......",
"URL={App_URL}/updateSomethingNeedingAddress/{userID}",
"Method=POST",
"EncType=raw",
"Snapshot=t999991.inf",
"Body={\r\n"
"\"Id\":\"{userID}\",\r\n"
"\"firstName\":\"{userFirstname}\",\r\n"
"\"lastName\":\"{userLastname}\",\r\n"
"\"streetName\":\"{userStreetName}\",\r\n"
"\"city\":\"{userCity}\",\r\n"
"\"province\":\"{userProvince}\",\r\n"
//This part will add the phone part if there is one after the postalCode. If no phone, the postalCode will be the last part of the json.
"\"postalCode\":\"{userPostalCode}\"{ifPhoneThenAddString}\r\n"
"}",
HEADERS,
"Name=Content-Type", "Value=application/json", ENDHEADER,
LAST);
...
...
...
return 0;

Related

UITextChecker code not giving correct result

I am using the standard method I think to check a word for validity. I have a 4 part array that is joined to make the word being verified.
I have this placed in my touches began func in a SpriteKit scene however it always gives me the answer "CORRECT SPELLING" even when it is not.
Curiously when I put the exact same bit of code into my did move to view func so it runs when the game starts it works perfectly well. The code is exactly the same except instead of the joined array I just create a let word = "WORD" before the code. So I am guessing the problem must be something to do with my joined array??
This is my code
let word = wordArray.joined()
let textChecker = UITextChecker()
let misspelledRange = textChecker.rangeOfMisspelledWord(
in: word, range: NSRange(0..<word.utf16.count), startingAt: 0, wrap: false, language: "en_US")
if misspelledRange.location != NSNotFound,
let guesses = textChecker.guesses(
forWordRange: misspelledRange, in: word, language: "en_US")
{
print("Guess: \(String(describing: guesses.first))") //Output is: Guess: Optional("Tester")
} else {
print("\(word) CORRECT SPELLING")
}
Turned out my issue was that UITextChecker does not like full caps!
Only accepts lower case spellings

Match every word, including non-a-z digits

I'm really struggling to get a regex working. All I want to do is something that would capture a string and its trailing space and put that as an entry into an array.
For example:
"RegExr #was created by gskinner.com, and is proudly hosted by Media Temple.
Edit the Expression & Text to see matches."
["RegExr ", "#was ", "created ", "by ", gskinner.com " ... "& " ... "matches. " etc...]
I'm trying to do the following in a React App:
console.log("matches are: ", message.match(/(\w+\s|#\w+\s|\s )/));
return message.match(/((\w+ ?))/);
// return message.split(" ");
I found that the split function was created some weird issues for me so I wanted just to have the matches function return an array of the results I specified above.
When I log out some attempts I just get weird results no matter what I try, like this:
e.g.
matches are: (2) ["Hey ", "Hey ", index: 0, input: "Hey Martin Im not sure how to make the font in this box bigger #ZX81", groups: undefined]
Can someone help it is really blocking some progress on my app.
To get all non-whitespace char chunks with any adjoining whitespace, you can use
message.match(/\s*\S+\s*/g)
See the regex demo. The g flag will make it extract all matches of
\s* - zero or more whitespace chars
\S+ - one or more non-whitespace chars
\s* - zero or more whitespace chars.
See a JavaScript demo:
const message = "RegExr #was created by gskinner.com, and is proudly hosted by Media Temple. Edit the Expression & Text to see matches.";
console.log(message.match(/\s*\S+\s*/g));

Find specific number of a word from the beginning in string

I've been gathering information using api calls from my jira. Information gathered is saved in a body file and it has the following content:
No tickets:
{"startAt":0,"maxResults":50,"total":0,"issues":[]}{"startAt":0,"maxResults":50,"total":0,"issues":[]}
One Ticket:
{"expand":"names,schema","startAt":0,"maxResults":50,"total":1,"issues":[{"expand":"operations,versionedRepresentations,editmeta,changelog,renderedFields","id":"456881","self":"https://myjira...com","key":"TICKET-1111","fields":{"summary":"[TICKET] New Test jira","created":"2018-12-17T01:47:09.000-0800"}}]}{"expand":"names,schema","startAt":0,"maxResults":50,"total":1,"issues":[{"expand":"operations,versionedRepresentations,editmeta,changelog,renderedFields","id":"456881","self":"https://myjira...com","key":"TICKET-1111","fields":{"summary":"[TICKET] New Test jira","created":"2018-12-17T01:47:09.000-0800"}}]}
Two Tickets:
{expand:schema,names,startAt:0,maxResults:50,total:2,issues:[{expand:operations,versionedRepresentations,editmeta,changelog,renderedFields,id:456881,self:https://myjira...com,key:TICKET-1111,fields:{summary:[TICKET] New Test jira,created:2018-12-17T01:47:09.000-0800}},{expand:operations,versionedRepresentations,editmeta,changelog,renderedFields,id:320281,self:https://myjira...com,key:TICKET-2222,fields:{summary:[TICKET] Test jira,created:2016-03-18T07:58:52.000-0700}}]}{expand:schema,names,startAt:0,maxResults:50,total:2,issues:[{expand:operations,versionedRepresentations,editmeta,changelog,renderedFields,id:456881,self:https://myjira...com,key:TICKET-1111,fields:{summary:[TICKET] New Test jira,created:2018-12-17T01:47:09.000-0800}},{expand:operations,versionedRepresentations,editmeta,changelog,renderedFields,id:320281,self:https://myjira...com,key:TICKET-2222,fields:{summary:[TICKET] Test jira,created:2016-03-18T07:58:52.000-0700}}]}
etc..
Using this code I've been able to gather total open tickets:
std::ifstream t("BodyOpenIssues.out");
std::string BodyString((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
// Removing Quotes
BodyString.erase(std::remove(BodyString.begin(), BodyString.end(), '"'), BodyString.end());
int Result = 0;
unsigned first = BodyString.find("total:");
unsigned last = BodyString.find(",issues");
std::string TotalOpenIssues = BodyString.substr(first + 6, last - (first + 6));
Result = std::stoi(TotalOpenIssues);
return Result;
Using a second function I'm trying to get the keys based on total open tickets.
if (GetOpenIssuesNumber() > 0)
{
std::ifstream t("BodyOpenIssues.out");
std::string BodyString((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
// Removing Quotes
BodyString.erase(std::remove(BodyString.begin(), BodyString.end(), '"'), BodyString.end());
unsigned first = BodyString.find("key:TICKET-");
unsigned last = BodyString.find(",fields");
std::string TotalOpenIssues = BodyString.substr(first + 11, last - (first + 11));
String^ Result = gcnew String(TotalOpenIssues.c_str());
return "TICKET-" + Result;
}
else
{
return "No open issues found";
}
What I mean is:
If Total is 1 to search from the beginning and find the first key TICKET-1111.
If Total is 2 to search from the beginning and get the first key TICKET-1111 then to continue from there and to find the next key TICKET-2222.
And based on that total to find that many keys in that string.
I got lost from all the casting between the types as ifstream reads the file and I save the result in std::string. After the find I save the result in System::String to use it in my Label.. I've been researching and found out that I can use char array but I can't make it dynamic based on BodyString.length().
If more information is required please let me know.
Any suggestions are really appreciated! Thank you in advance!
I went for nlohmann json library. It has everything I need. Thank you Walnut!
These are formatted as JSON. You should use a JSON library for C++ and parse the files with that. Using search/replace is unnecessary complicated and you will likely run into corner cases you haven't considered sooner or later (do you really want the code to randomly miss tickets, etc.?). Also String^ is not C++. Are you writing C++/CLI instead of C++? If so, please tag c++-cli instead of c++. – walnut

Need to check whether any extension is present before query string

I have written the code to check the query string
Logic::if query string is "?" should remove all the characters from the query string and print the vailid URL.
char str[] = "http://john.org/test.mp4?iufjdlwle";
char *pch;
pch = strtok(str,"?");
printf("%s\n",pch);
Output::
bash-3.2$ ./querystring
http://john.com/test.mp4
But i have to check one more case
Need to get the URL only if there is any extensions present before query string?
if No extensions are present before the query string,need to skip.
I have tried this way,
continuation of the code
char *final;
final = pch+(strlen(pch)-3);
printf("%s\n",final);
if(strcasecmp(p,"mp4"))
printf("falure case\n");
else
printf("Success case\n");
It will work for .mp4 extension alone.
Incase if i'm getting *.mpeg or *.m3u8 or *.flv as an extensions,it will fail.
Can someone guide me how to solve this problem and make it working?
A query string is what starts after a question mark ?, fine.
You should try to define what an extension is. For me, it is what can happen after a dot (.) in the last component of the url, where the components are delimited with slashes (/)
So you should do:
first remove the possible query string including the initial ?
then locate the last /
then locate the last . that occurs after the last /
If you find one, it is the starting point of the extension.
So assuming pch contains the url without any query string, you can do:
char * ix = strrchr(pch, '/');
if (ix == NULL) {
// an URL without / is rather weird, better report and abort
...
}
ix = strrchr(ix, '.');
if (ix == NULL) {
// no extension here: ignore the url
...
}
else {
// found an URL containing an extension: process it
// ix+1 points to the extension
...
}

Parse add string to array swift

My question is this with an example from the parse docs:
You have in parse the column with all kind of types, like string, array, etc.
Now I have the following kind of code:
var gameScore = PFObject(className:"GameScore")
gameScore["score"] = 1337
gameScore["playerName"] = "Sean Plott"
gameScore.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}
Ok now I want to save another score behind the first score: 1337.
So when I retrieve from parse it will look like this: Sean: 1337, 1207.
Or something like that when I retrieve the name and scores. I have in parse it already set to be an array.
So my question is: How do I add a string to an array in parse.
Thank you beforehand.
You need "score" to be an Array in your DB. Then in your code, you do this:
gameScore.addObject([1337], forKey:"score")

Resources