-1

I have a text file as below and I want to get only the numbers below column rank:

SKYRain  LND(4)    VA(x)      ZZ(x)     NUM(n)   Rank  ll ListOfNames                                                   
-------  ------    -----      -----     ------   ----  -- -----------                                                   
   1002      75   283680     185836   1,111.50  19268   1 Jack                         
   4308    1100   175896     195404     751.70   6384   1 Sara                                                      
   3070     252  1044788     884160     682.94  18924   1 Robert                                                        
   3187     206   852280      97932     535.83  16472   1 Harry  

I just want the numbers below the rank below:

19268
6384
18924
16472

Is there a way?

fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
Inferno
  • 41
  • 5

2 Answers2

3

You have a fixed width text file. Just can simply use SubString():

public class Program{
    public static void Main(){
        string aLineOfYourTextFile = "   1002      75   283680     185836   1,111.50  19268   1 Jack ";
        Console.WriteLine(aLineOfYourTextFile.Substring(48,5));
    }
}

You can also use Split():

public class Program{
    public static void Main(){
        string aLineOfYourTextFile = "   1002      75   283680     185836   1,111.50  19268   1 Jack ";
        var columns = aLineOfYourTextFile.Split(new[]{" "}, StringSplitOptions.RemoveEmptyEntries);
        Console.WriteLine(columns[5]);
    }
}
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
  • But the numbers and distances are not fixed and change in later times – Inferno Jan 05 '23 at 18:30
  • @Inferno The Split() method should still work – Thomas Weller Jan 05 '23 at 18:31
  • While I believe reading the file as regular CSV is much better option (and I picked duplicate for that), indeed String.Split is an approach to this particular case. @Inferno please note that it is expected to try things out before asking a question (including asking for clarification in the comment) - I don't see why you still have that question after running the code suggested by Thomas Weller. – Alexei Levenkov Jan 05 '23 at 18:37
  • @ThomasWeller The second code worked, Thanks – Inferno Jan 05 '23 at 19:27
0
  • read and skip 2 lines
  • read next line, split on " ", select 5th entry, convert to int
  • repeat above till EOF
pm100
  • 48,078
  • 23
  • 82
  • 145