Forum Discussion

mpw83's avatar
mpw83
Contributor
6 years ago
Solved

How to read the content of a multi line string and process

I am getting the following text as a response. 

02023009005032000 290609       OYMZY 
03023009005609502 0500047405000OAYMOZEY           00000000000000025    IZVTOADV    IZVTOADV   OAYMOZEY 
039930090056095               0047405000

This string contains different details. For example, the first number set in the first line `02023009005032000` represents the person number. 
I want to read line by line and store the numbers in different variables. 
E.g

For line no one (02023009005032000 290609       OYMZY )

 

Var1Line1 = 02023009005032000
Var2Line1 = 290609

Var3Line1 = OYMZY .. etc 

For line no two (03023009005609502 0500047405000OAYMOZEY           00000000000000025    IZVTOADV    IZVTOADV   OAYMOZEY )

Var1Line2 = 03023009005609502
Var2Line2 = 0500047405000OAYMOZEY

Var3Line2 = 00000000000000025

Var4Line2 = IZVTOADV

Var5Line2 = IZVTOADV

Var6Line2 = OAYMOZEY


I could get the lines as follows, 

def docContent = context.expand( '${#TestCase#DocContent}' )
def arr = docContent.split("\r");

Then how I can get the numbers separately which belong to each line? The other problem is the spaces between content are not the same. Otherwise could split by space 

def docContent = context.expand( '${#TestCase#DocContent}' ) 
def arr = docContent.split("\r");

for (int i = 0; i < arr.length; i++) { def a = arr[i] String[] vals = a.split(" ") for (int j = 0; j < vals.length; j++){ log.info(vals[j]) } }

What is the best way to do this? Help much appreciated