We help IT Professionals succeed at work.
Get Started

How to process a txt file for parsing with a function in C#

Skale
Skale asked
on
93 Views
Last Modified: 2019-12-22
Hello,

I've a txt file like below and i'd like to get some informations from it with a function but need a expert help for parsing.

  139 142    :No. nodes, No. modes:
 part                                            
      new modal                                 =                                                                                 
           refmod                                
                mass                            = 2.000D+03
                nelastq                         = 142
                ielastq (   1)                  = Eigen Mode    7 :        3.895 Hz
                ielastq (   2)                  = Eigen Mode    8 :        8.914 Hz
                ielastq (   3)                  = Eigen Mode    9 :       10.455 Hz
                ielastq (   4)                  = Eigen Mode   10 :       10.633 Hz
                ielastq (   5)                  = Eigen Mode   11 :       14.134 Hz
                ielastq (   6)                  = Eigen Mode   12 :       14.230 Hz
                ielastq (   7)                  = Eigen Mode   13 :       14.839 Hz
                ielastq (   8)                  = Eigen Mode   14 :       15.543 Hz
                ielastq (   9)                  = Eigen Mode   15 :       16.810 Hz
                ielastq (  10)                  = Eigen Mode   16 :       16.921 Hz
                ielastq (  11)                  = Eigen Mode   17 :       17.858 Hz
                ielastq (  12)                  = Eigen Mode   18 :       18.822 Hz
                ielastq (  13)                  = Eigen Mode   19 :       19.006 Hz
                ielastq (  14)                  = Eigen Mode   20 :       19.335 Hz
                ielastq (  15)                  = Eigen Mode   21 :       19.430 Hz
                ielastq (  16)                  = IRM           1 :       59.876 Hz
                ielastq (  17)                  = IRM           2 :       60.495 Hz
                ielastq (  18)                  = IRM           3 :       61.735 Hz
                ielastq (  19)                  = IRM           4 :       64.041 Hz
                ielastq (  20)                  = IRM           5 :       67.065 Hz
                ielastq (  21)                  = IRM           6 :       67.663 Hz
                ielastq (  22)                  = IRM           7 :       69.528 Hz
           end refmod   
	   
			Some Text Data
			.
			.
			.     

Open in new window

           

I'd like to get informations from  ielastq (   *id*) rows.

If there's a function like

public static string[] GetIElastiq(int id)
{
// some code here
}

Open in new window


if i wrote id 10 that function i'd like to get result as [ {Eigen Mode}, {16}, {16.921} ]

It'll found the row:          
   ielastq (  10)                  = Eigen Mode   16 :       16.921 Hz

Open in new window


and parse for me.

The values always between "refmod" and "end refmod" so Textreader only can focus this region.

Any help would be very great!!

Thank you.
Comment
Watch Question
Senior Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 2 Answers and 11 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE