Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

vb.net - display names from text

hello,
I have a text file with first names each one line by line..
I would like to know how can i display the first 10 records and delete them.

        Dim x As Integer
        For x = 1 To 10
                Call Get_Names(x)
        Next x

right now I have two functions one that read the first line and one that deletes the first one..
but doing this it has to open the file 10 times to read an another 10 times for deletes..
Avatar of Anuroopsundd
Anuroopsundd
Flag of India image

For a = 1 To 10
call Get_Names(x)
 
 Next


2. another option

Do While x<11
call Get_Names(x)
Loop
why not read all the lines, perform our action and then delete the file completely:-
var lines = File.ReadAllLines("FilePath");

            var loopCounter = lines.Count()/10 + (lines.Count()%10 > 0 ? 1 : 0);

            for(int i=0;i<loopCounter;i++)
            {
                lines.Take(10).ToList().ForEach(Console.WriteLine);
            }

            File.Delete("FilePath");

Open in new window

Avatar of XK8ER

ASKER

no i dont want to read the whole file just first 10 lines then remove them
ASKER CERTIFIED SOLUTION
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you do not want to read all the lines, easily achieved by amending this line to just read 10 lines.

 TheFileLines.AddRange(System.IO.File.ReadAllLines(FileAddress))