cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Contributor

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 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

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

@mpw83 ,

 

Here you go:

https://github.com/nmrao/soapUIGroovyScripts/blob/697b1885c783258c7381455cadfd7f6e4d5f2a4c/groovy/Sp...

 

You will be able to access values by looping thru the "data" which is an arry



Regards,
Rao.

View solution in original post

8 REPLIES 8
Community Hero

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

More details of the use case would help to understand better about the problem.


Regards,
Rao.
Contributor

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

Hi @nmrao , Sorry and I added more details. Please let me know if you need more details. Thanks a lot

Community Manager

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

Thanks for the clarification, mpw83!

 

@nmrao, do you have any suggestions based on the updated information? 

 

 



Sonya Mihaljova
Community and Education Specialist
Enroll at the SmartBear Academy today and learn our products via exclusive video courses.
Community Hero

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

Thank you, but that is not helpful.

Would you mind showing entire response (hoping that is a rest response), attach in a file? Need not be same response but same structure.

Also explain about what you wanted to do with the data that you read?
May be you can ask your service provider or your team (if developed in house) why the response is not providing in a standard format so that data can be consumed easily if possible.


Regards,
Rao.
Contributor

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

@nmrao , thanks for the reply. I have attached the HTML and XML responses. these are the bank files and the format can not be changed. The spaces between the character should not be changed. 

What I am trying to do is validating these files. 

 As I mentioned I want to get the blok of chars and validate. 

E.g

the first block - '12123109005032001' and validate. 

Get the second block - '290619' and validate .. etc ...

 

Community Hero

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

@mpw83 ,

 

Here you go:

https://github.com/nmrao/soapUIGroovyScripts/blob/697b1885c783258c7381455cadfd7f6e4d5f2a4c/groovy/Sp...

 

You will be able to access values by looping thru the "data" which is an arry



Regards,
Rao.

View solution in original post

Contributor

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

@nmrao , Thanks this is what I want

Highlighted
Community Hero

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

Thank you for the patience and followup.


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors