We are building a new experience for our SmartBear Community.
This site is now read-only. You can still browse and search as usual. Learn More
This site is now read-only. You can still browse and search as usual. Learn More
Helen's reply got me thinking... Could we just use the powers of JavaScript directly?
function test()
{
var str = "type1=12345678901234567890111&type2=3.0.00&type3=1234567811";
var strarr = str.split('&');
for (var i = 0; i < strarr.length; i++) {
var typearr = strarr[i].split('=');
Log.Message(strarr[i]);
switch (typearr[0]) {
case 'type1':
Log.Message("TYPE1: length = " + typearr[1].length);
break;
case 'type2':
Log.Message("TYPE2: length = " + typearr[1].length);
break;
case 'type3':
Log.Message("TYPE3: length = " + typearr[1].length);
break;
default:
Log.Message("unrecognized type");
break;
}
}
}
produces
Hi Marsha so does this imply that in my string I need to do a find and replace of the & and replace it with | for this to work?
Helen's reply got me thinking... Could we just use the powers of JavaScript directly?
function test()
{
var str = "type1=12345678901234567890111&type2=3.0.00&type3=1234567811";
var strarr = str.split('&');
for (var i = 0; i < strarr.length; i++) {
var typearr = strarr[i].split('=');
Log.Message(strarr[i]);
switch (typearr[0]) {
case 'type1':
Log.Message("TYPE1: length = " + typearr[1].length);
break;
case 'type2':
Log.Message("TYPE2: length = " + typearr[1].length);
break;
case 'type3':
Log.Message("TYPE3: length = " + typearr[1].length);
break;
default:
Log.Message("unrecognized type");
break;
}
}
}
produces
Thanks, Joe! Your solution is even better, because it doesn't have external depenencies.
joseph_michaud wrote:
Helen's reply got me thinking... Could we just use the powers of JavaScript directly?
function test() { var str = "type1=12345678901234567890111&type2=3.0.00&type3=1234567811"; var strarr = str.split('&'); for (var i = 0; i < strarr.length; i++) { var typearr = strarr[i].split('='); Log.Message(strarr[i]); switch (typearr[0]) { case 'type1': Log.Message("TYPE1: length = " + typearr[1].length); break; case 'type2': Log.Message("TYPE2: length = " + typearr[1].length); break; case 'type3': Log.Message("TYPE3: length = " + typearr[1].length); break; default: Log.Message("unrecognized type"); break; } } }produces
JB -
It's supposed to let you reset your delimiter, so try what I have with the & and see if it works for you. I am using an old version of TestComplete so maybe it's not implemented for me.
Helen, Joseph -
The original post had a request to try to do this in keyword tests. Would you really put all that code in a code snippet? Also, do you have an idea why resetting the delimiter didn't work for me?
It looks that way in my example but when I ran it myself, the delimiter would always be |
I changed from & to | in my test so I could see if the rest of the stuff worked.
What version are you using?
Tried that and it worked for me. Let's continue this offline.
If I absolutely had to use a keyword test, then the following expressions could be used to pick out the lengths of the three types
KeywordTests.Test1.Variables.Var1.split('&')[0].split('=')[1].length
KeywordTests.Test1.Variables.Var1.split('&')[1].split('=')[1].length
KeywordTests.Test1.Variables.Var1.split('&')[2].split('=')[1].length
As for not being able to set the delimiter... I think you *are* setting the delimiter properly but your example shows you calling GetLength() rather than GetListLength().
9.31