-9

I have a string of text that I am trying to break into pieces in Loadrunner Here are two possible combinations of text

309-95-90570-0243-023-0030

222-627-90570-0365-042-0031

I need to be able to break each section that is inside of the "-" into separate variables.

For Example the variables need to be

First Variable - 309 from the first set and 222 from the second set

It gets tricky here for the second variable bc in the first example it contains two characters where in the second example it contains three characters.

Second Variable - 95 from the first set and 627 from the second set

Third Variable - 90570 from the first set and 90570 from the second set

Does anyone know how I would accomplish this?

Dominik Sandjaja
  • 6,326
  • 6
  • 52
  • 77
bfali
  • 1
  • 1
  • 5
    First you need to decide on a language and then you need to show some effort on your own. We are not here to do your work for you, but rather to help out with specific issues you are stumped on yourself. – Dragondraikk Aug 05 '15 at 12:56
  • @KingofMasses, how could this possibly be a duplicate of something concerning email addresses? – Manu Aug 05 '15 at 13:15
  • LoadRunner is a C language product, so you may want a solution in C. There are a number of possible solutions, including the use of strtok() with the '-' as a token. strstr() could be used to locate the first instance of the '-' and then strncpy to copy the first n characters to another string. You can also play move the pointer on the original string in a recursive fashion &pointerstringvariablename[offset] to get the last portion of the string beginning at the offset and reuse strstr() and strncpy(). C is a foundation class skill for the use of LoadRunner, as is Java for JMETER – James Pulley Aug 06 '15 at 02:11

2 Answers2

0

Simply use split function. Example:

String foo = "309-95-90570-0243-023-0030";
String[] bar = foo.split("-"); 
for (String s : bar) {
     System.out.println(s);
}

Also you could always make values from string to int with Integer.parseInt(value);

Georgi Stoyanov
  • 469
  • 1
  • 5
  • 24
0

Here is a function that will do the work.

    public static List<List<string>> GetSplitedValues(IList<string> _inputList )
    {

        string[] splitwords = _inputList[0].Split('-');
        List<string>[] _ouputList = new List<string>[splitwords.Length];
        for(int i=0;i<_ouputList.Length;i++)
        {
            _ouputList[i]=new List<string>();
        }
        for (int i = 0; i < _inputList.Count; i++)
        {
            string[] _splitwords = _inputList[i].Split('-');
            for (int j = 0; j < splitwords.Length; j++)
            {
                _ouputList[j].Add(_splitwords[j]);
            }
        }
        List<List<string> >_temp= new List<List<string>>();
        _temp.AddRange(_ouputList);
        return _temp;



    }

and you can test using these lines

 List<string> _a=new List<string>();
            _a.Add("222-627-90570-0365-042-0031");
            _a.Add("309-95-90570-0243-023-0030");
            List<List<string>> _o = GetSplitedValues(_a);
            foreach (var list in _o)
            {
                foreach (var str in list)
                {
                    Console.Write(str);
                }
                Console.WriteLine();
            }
ankyAS
  • 301
  • 2
  • 11