Click here to Skip to main content
14,739,804 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on data collection from a simple text file as shown below:


* GROUP No.1   *
Result: PASS
Remark:
Example No.: 11


* GROUP No.2   *
Result: PASS
Remark:
Example No.: 12


* GROUP No.3   *
Result: PASS
Remark:
Example No.: 13


* GROUP No.4   *
Result: PASS
Remark:
Example No.: 14


* GROUP No.5   *
Result: FAIL
Remark:
Example No.:27

Subject	PaperId	Point	
001260	001	30
001261	002	20
001262	003	10


* GROUP No.6   *
Result: FAIL
Remark:
Example No.:16


I want to read the data group by the * GROUP No.X * into the array. Only if the result is FAIL there will have extra information.

how can I do it in VB.net?


i tried as I posted the codes but the reault go crazy

What I have tried:

Dim arrayCut As String() = NoNLText.Split("* GROUP ")

        For Each p As String In arrayCut
            txtSplittedText.Text = p
            MsgBox("Result")
        Next
Posted
Updated 3-Nov-20 21:09pm

1 solution

Instead of a simple Split, I'd suggest that you look at a Regex: VB.Net - Regular Expressions - Tutorialspoint[^] - they can be a lot more flexible and powerful. But they are hard to learn.

Instead of either, read the file as lines, and process each line, discarding blank lines
When a line starts with "* GROUP No." it's the start of a Group, and it's trivial to get the group number with Substring and TryParse.
The following line should start with "RESULT":" and again it's trivial to get the result code.
Collect the Remark and Example data, ignore blank lines
If the result code is FAIL, then collect the additional info, otherwise ignore it until you get a fresh GROUP.

Me? I'd create a class to hold the info, and create a new instance to fill in each time I got a new Group - adding it to a collection such as a List. Getting all the info I can, because at some later point the task will change and require some of it, and it's easier to organise it to start with. The additional data for a FAIL code would be a collection of it's own within the class I created.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900