WeixiangYan/CodeTransOcean huggingface dataset:
Task: Remove lines from a file

C: #include <stdio.h>
#include <stdlib.h> 
#include <string.h> 


#define ERROR(fmt, arg) return fprintf(stderr, fmt "\n", arg)

int main(int argc, char **argv)
{
    FILE *fp;
    char *buf;
    size_t sz;
    int start, count, lines = 1;
    int dest = 0, src = 0, pos = -1;

    
    if (argc != 4)
        ERROR("Usage: %s <file> <start> <count>", argv[0]);

    if ((count = atoi(argv[3])) < 1) 
        return 0;

    if ((start = atoi(argv[2])) < 1)
        ERROR("Error: <start> (%d) must be positive", start);

    if ((fp = fopen(argv[1], "r")) == NULL)
        ERROR("No such file: %s", argv[1]);

    
    fseek(fp, 0, SEEK_END);
    sz = ftell(fp);
    buf = malloc(sz + 1);
    rewind(fp);

    
    while ((buf[++pos] = fgetc(fp)) != EOF) {
        if (buf[pos] == '\n') {
            ++lines;
            if (lines == start) dest = pos + 1;
            if (lines == start + count) src = pos + 1;
        }
    }

    
    if (start + count > lines) {
        free(buf);
        fclose(fp);
        ERROR("Error: invalid parameters for file with %d lines", --lines);
    }

    
    memmove(buf + dest, buf + src, pos - src);

    
    freopen(argv[1], "w", fp);
    fwrite(buf, pos - src + dest, 1, fp);

    free(buf);
    fclose(fp);
    return 0;
}
Task: Remove lines from a file



C#: using System;
using System.IO;
using System.Linq;

public class Rosetta
{
    public static void Main() => RemoveLines("foobar.txt", start: 1, count: 2);

    static void RemoveLines(string filename, int start, int count = 1) =>
        File.WriteAllLines(filename, File.ReadAllLines(filename)
            .Where((line, index) => index < start - 1 || index >= start + count - 1));
}
Task: Remove lines from a file


C++: #include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
#include <list>

void deleteLines( const std::string & , int , int ) ;

int main( int argc, char * argv[ ] ) {
   if ( argc != 4 ) {
      std::cerr << "Error! Invoke with <deletelines filename startline skipnumber>!\n" ;
      return 1 ;
   }
   std::string filename( argv[ 1 ] ) ;
   int startfrom = atoi( argv[ 2 ] ) ;
   int howmany = atoi( argv[ 3 ] ) ;
   deleteLines ( filename , startfrom , howmany ) ;
   return 0 ;
}

void deleteLines( const std::string & filename , int start , int skip ) {
   std::ifstream infile( filename.c_str( ) , std::ios::in ) ;
   if ( infile.is_open( ) ) {
      std::string line ;
      std::list<std::string> filelines ;
      while ( infile ) {
	 getline( infile , line ) ;
	 filelines.push_back( line ) ;
      }
      infile.close( ) ;
      if ( start > filelines.size( ) ) {
	 std::cerr << "Error! Starting to delete lines past the end of the file!\n" ;
	 return ;
      }
      if ( ( start + skip ) > filelines.size( ) ) {
	 std::cerr << "Error! Trying to delete lines past the end of the file!\n" ;
	 return ;
      }
      std::list<std::string>::iterator deletebegin = filelines.begin( ) , deleteend ;
      for ( int i = 1 ; i < start ; i++ )
	 deletebegin++ ;
      deleteend = deletebegin ;
      for( int i = 0 ; i < skip ; i++ )
	 deleteend++ ;
      filelines.erase( deletebegin , deleteend ) ;
      std::ofstream outfile( filename.c_str( ) , std::ios::out | std::ios::trunc ) ;
      if ( outfile.is_open( ) ) {
	 for ( std::list<std::string>::const_iterator sli = filelines.begin( ) ;
	       sli != filelines.end( ) ; sli++ )
	    outfile << *sli << "\n" ;
      }
      outfile.close( ) ;
   }
   else {
      std::cerr << "Error! Could not find file " << filename << " !\n" ;
      return ;
   }
}
Task: Remove lines from a file





Java: import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class RemoveLines
{
	public static void main(String[] args)
	{
		
		String filename="foobar.txt";
		
		int startline=1;
		
		int numlines=2;
		
		RemoveLines now=new RemoveLines();
		now.delete(filename,startline,numlines);
	}
	void delete(String filename, int startline, int numlines)
	{
		try
		{
			BufferedReader br=new BufferedReader(new FileReader(filename));
			
			
			StringBuffer sb=new StringBuffer("");
			
			
			int linenumber=1;
			String line;
			
			while((line=br.readLine())!=null)
			{
				
				if(linenumber<startline||linenumber>=startline+numlines)
					sb.append(line+"\n");
				linenumber++;
			}
			if(startline+numlines>linenumber)
				System.out.println("End of file reached.");
			br.close();
			
			FileWriter fw=new FileWriter(new File(filename));
			
			fw.write(sb.toString());
			fw.close();
		}
		catch (Exception e)
		{
			System.out.println("Something went horribly wrong: "+e.getMessage());
		}
	}
}
Task: Remove lines from a file







Python: 

import fileinput, sys

fname, start, count = sys.argv[1:4]
start, count = int(start), int(count)

for line in fileinput.input(fname, inplace=1, backup='.orig'):
    if start <= fileinput.lineno() < start + count:
        pass
    else:
        print line.rstrip("\n")
fileinput.close()
Task: Remove lines from a file








VB: Option Explicit

Sub Main()
   
   RemoveLines "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 11, 5
   
   RemoveLines "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 8, 5
   
   RemoveLines "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 3, 5
End Sub

Private Sub RemoveLines(StrFile As String, StartLine As Long, NumberOfLines As Long)
Dim Nb As Integer, s As String, count As Long, out As String
   Nb = FreeFile
   Open StrFile For Input As #Nb
      While Not EOF(Nb)
         count = count + 1
         Line Input #Nb, s
         If count < StartLine Or count >= StartLine + NumberOfLines Then
            out = out & s & vbCrLf
         End If
      Wend
   Close #Nb
   If StartLine >= count Then
      MsgBox "The file contains only " & count & " lines"
   ElseIf StartLine + NumberOfLines > count Then
      MsgBox "You only can remove " & count - StartLine & " lines"
   Else
      Nb = FreeFile
      Open StrFile For Output As #Nb
         Print #Nb, out
      Close #Nb
   End If
End Sub
Task: Remove lines from a file




Go: package main

import (
    "bytes"
    "errors"
    "fmt"
    "io/ioutil"
    "os"
)

func main() {
    if err := removeLines("foobar.txt", 1, 2); err != nil {
        fmt.Println(err)
    }
}

func removeLines(fn string, start, n int) (err error) {
    if start < 1 {
        return errors.New("invalid request.  line numbers start at 1.")
    }
    if n < 0 {
        return errors.New("invalid request.  negative number to remove.")
    }
    var f *os.File
    if f, err = os.OpenFile(fn, os.O_RDWR, 0); err != nil {
        return
    }
    defer func() {
        if cErr := f.Close(); err == nil {
            err = cErr
        }
    }()
    var b []byte
    if b, err = ioutil.ReadAll(f); err != nil {
        return
    }
    cut, ok := skip(b, start-1)
    if !ok {
        return fmt.Errorf("less than %d lines", start)
    }
    if n == 0 {
        return nil
    }
    tail, ok := skip(cut, n)
    if !ok {
        return fmt.Errorf("less than %d lines after line %d", n, start)
    }
    t := int64(len(b) - len(cut))
    if err = f.Truncate(t); err != nil {
        return
    }
    if len(tail) > 0 {
        _, err = f.WriteAt(tail, t)
    }
    return
}

func skip(b []byte, n int) ([]byte, bool) {
    for ; n > 0; n-- {
        if len(b) == 0 {
            return nil, false
        }
        x := bytes.IndexByte(b, '\n')
        if x < 0 {
            x = len(b)
        } else {
            x++
        }
        b = b[x:]
    }
    return b, true
}
Task: Remove lines from a file



C#: using System;
using System.IO;
using System.Linq;

public class Rosetta
{
    public static void Main() => RemoveLines("foobar.txt", start: 1, count: 2);

    static void RemoveLines(string filename, int start, int count = 1) =>
        File.WriteAllLines(filename, File.ReadAllLines(filename)
            .Where((line, index) => index < start - 1 || index >= start + count - 1));
}








Fortran:       SUBROUTINE CROAK(GASP)	
       CHARACTER*(*) GASP	
        WRITE (6,*) "Oh dear. ",GASP	
        STOP "++ungood."	
      END			

      SUBROUTINE FILEHACK(FNAME,IST,N)
       CHARACTER*(*) FNAME	
       INTEGER IST		
       INTEGER N		
       INTEGER ENUFF,L		
       PARAMETER (ENUFF = 66666)
       CHARACTER*(ENUFF) ALINE	
       INTEGER NREC		
       INTEGER F,T		
       PARAMETER (F=66,T=67)	
       LOGICAL EXIST
        IF (FNAME.EQ."") CALL CROAK("Blank file name
        IF (IST.LE.0)    CALL CROAK("First record must be positive
        IF (N.LE.0)      CALL CROAK("Remove count must be positive
        INQUIRE(FILE = FNAME, EXIST = EXIST)	
        IF (.NOT.EXIST) CALL CROAK("Can't find a file called "//FNAME)	
        OPEN (F,FILE=FNAME,STATUS="OLD",ACTION="READ",FORM="FORMATTED")	
        OPEN (T,STATUS="SCRATCH",FORM="FORMATTED")	
        NREC = 0		
Copy the desired records to a temporary file.
   10   READ (F,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11   FORMAT (Q,A)		
        IF (L.GT.ENUFF) CALL CROAK("Ow
        NREC = NREC + 1		
        IF (NREC.LT.IST .OR. NREC.GE.IST + N) WRITE (T,12) ALINE(1:L)	
   12   FORMAT (A)		
        GO TO 10		
Convert from input to output...
   20   IF (NREC.LT.IST + N) CALL CROAK("Insufficient records
        REWIND T		
        CLOSE(F)		
        OPEN (F,FILE=FNAME,FORM="FORMATTED",	
     1   ACTION="WRITE",STATUS="REPLACE")	
Copy from the temporary file.
   21   READ (T,11,END = 30) L,ALINE(1:L)	
        WRITE (F,12) ALINE(1:L)			
        GO TO 21		
Completed.
   30   CLOSE(T)		
        CLOSE(F)		
      END		

      PROGRAM CHOPPER
       CALL FILEHACK("foobar.txt",1,2)
      END
Task: Remove lines from a file

C: #include <stdio.h>
#include <stdlib.h> 
#include <string.h> 


#define ERROR(fmt, arg) return fprintf(stderr, fmt "\n", arg)

int main(int argc, char **argv)
{
    FILE *fp;
    char *buf;
    size_t sz;
    int start, count, lines = 1;
    int dest = 0, src = 0, pos = -1;

    
    if (argc != 4)
        ERROR("Usage: %s <file> <start> <count>", argv[0]);

    if ((count = atoi(argv[3])) < 1) 
        return 0;

    if ((start = atoi(argv[2])) < 1)
        ERROR("Error: <start> (%d) must be positive", start);

    if ((fp = fopen(argv[1], "r")) == NULL)
        ERROR("No such file: %s", argv[1]);

    
    fseek(fp, 0, SEEK_END);
    sz = ftell(fp);
    buf = malloc(sz + 1);
    rewind(fp);

    
    while ((buf[++pos] = fgetc(fp)) != EOF) {
        if (buf[pos] == '\n') {
            ++lines;
            if (lines == start) dest = pos + 1;
            if (lines == start + count) src = pos + 1;
        }
    }

    
    if (start + count > lines) {
        free(buf);
        fclose(fp);
        ERROR("Error: invalid parameters for file with %d lines", --lines);
    }

    
    memmove(buf + dest, buf + src, pos - src);

    
    freopen(argv[1], "w", fp);
    fwrite(buf, pos - src + dest, 1, fp);

    free(buf);
    fclose(fp);
    return 0;
}










Fortran:       SUBROUTINE CROAK(GASP)	
       CHARACTER*(*) GASP	
        WRITE (6,*) "Oh dear. ",GASP	
        STOP "++ungood."	
      END			

      SUBROUTINE FILEHACK(FNAME,IST,N)
       CHARACTER*(*) FNAME	
       INTEGER IST		
       INTEGER N		
       INTEGER ENUFF,L		
       PARAMETER (ENUFF = 66666)
       CHARACTER*(ENUFF) ALINE	
       INTEGER NREC		
       INTEGER F,T		
       PARAMETER (F=66,T=67)	
       LOGICAL EXIST
        IF (FNAME.EQ."") CALL CROAK("Blank file name
        IF (IST.LE.0)    CALL CROAK("First record must be positive
        IF (N.LE.0)      CALL CROAK("Remove count must be positive
        INQUIRE(FILE = FNAME, EXIST = EXIST)	
        IF (.NOT.EXIST) CALL CROAK("Can't find a file called "//FNAME)	
        OPEN (F,FILE=FNAME,STATUS="OLD",ACTION="READ",FORM="FORMATTED")	
        OPEN (T,STATUS="SCRATCH",FORM="FORMATTED")	
        NREC = 0		
Copy the desired records to a temporary file.
   10   READ (F,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11   FORMAT (Q,A)		
        IF (L.GT.ENUFF) CALL CROAK("Ow
        NREC = NREC + 1		
        IF (NREC.LT.IST .OR. NREC.GE.IST + N) WRITE (T,12) ALINE(1:L)	
   12   FORMAT (A)		
        GO TO 10		
Convert from input to output...
   20   IF (NREC.LT.IST + N) CALL CROAK("Insufficient records
        REWIND T		
        CLOSE(F)		
        OPEN (F,FILE=FNAME,FORM="FORMATTED",	
     1   ACTION="WRITE",STATUS="REPLACE")	
Copy from the temporary file.
   21   READ (T,11,END = 30) L,ALINE(1:L)	
        WRITE (F,12) ALINE(1:L)			
        GO TO 21		
Completed.
   30   CLOSE(T)		
        CLOSE(F)		
      END		

      PROGRAM CHOPPER
       CALL FILEHACK("foobar.txt",1,2)
      END
Task: Remove lines from a file




Go: package main

import (
    "bytes"
    "errors"
    "fmt"
    "io/ioutil"
    "os"
)

func main() {
    if err := removeLines("foobar.txt", 1, 2); err != nil {
        fmt.Println(err)
    }
}

func removeLines(fn string, start, n int) (err error) {
    if start < 1 {
        return errors.New("invalid request.  line numbers start at 1.")
    }
    if n < 0 {
        return errors.New("invalid request.  negative number to remove.")
    }
    var f *os.File
    if f, err = os.OpenFile(fn, os.O_RDWR, 0); err != nil {
        return
    }
    defer func() {
        if cErr := f.Close(); err == nil {
            err = cErr
        }
    }()
    var b []byte
    if b, err = ioutil.ReadAll(f); err != nil {
        return
    }
    cut, ok := skip(b, start-1)
    if !ok {
        return fmt.Errorf("less than %d lines", start)
    }
    if n == 0 {
        return nil
    }
    tail, ok := skip(cut, n)
    if !ok {
        return fmt.Errorf("less than %d lines after line %d", n, start)
    }
    t := int64(len(b) - len(cut))
    if err = f.Truncate(t); err != nil {
        return
    }
    if len(tail) > 0 {
        _, err = f.WriteAt(tail, t)
    }
    return
}

func skip(b []byte, n int) ([]byte, bool) {
    for ; n > 0; n-- {
        if len(b) == 0 {
            return nil, false
        }
        x := bytes.IndexByte(b, '\n')
        if x < 0 {
            x = len(b)
        } else {
            x++
        }
        b = b[x:]
    }
    return b, true
}







Fortran:       SUBROUTINE CROAK(GASP)	
       CHARACTER*(*) GASP	
        WRITE (6,*) "Oh dear. ",GASP	
        STOP "++ungood."	
      END			

      SUBROUTINE FILEHACK(FNAME,IST,N)
       CHARACTER*(*) FNAME	
       INTEGER IST		
       INTEGER N		
       INTEGER ENUFF,L		
       PARAMETER (ENUFF = 66666)
       CHARACTER*(ENUFF) ALINE	
       INTEGER NREC		
       INTEGER F,T		
       PARAMETER (F=66,T=67)	
       LOGICAL EXIST
        IF (FNAME.EQ."") CALL CROAK("Blank file name
        IF (IST.LE.0)    CALL CROAK("First record must be positive
        IF (N.LE.0)      CALL CROAK("Remove count must be positive
        INQUIRE(FILE = FNAME, EXIST = EXIST)	
        IF (.NOT.EXIST) CALL CROAK("Can't find a file called "//FNAME)	
        OPEN (F,FILE=FNAME,STATUS="OLD",ACTION="READ",FORM="FORMATTED")	
        OPEN (T,STATUS="SCRATCH",FORM="FORMATTED")	
        NREC = 0		
Copy the desired records to a temporary file.
   10   READ (F,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11   FORMAT (Q,A)		
        IF (L.GT.ENUFF) CALL CROAK("Ow
        NREC = NREC + 1		
        IF (NREC.LT.IST .OR. NREC.GE.IST + N) WRITE (T,12) ALINE(1:L)	
   12   FORMAT (A)		
        GO TO 10		
Convert from input to output...
   20   IF (NREC.LT.IST + N) CALL CROAK("Insufficient records
        REWIND T		
        CLOSE(F)		
        OPEN (F,FILE=FNAME,FORM="FORMATTED",	
     1   ACTION="WRITE",STATUS="REPLACE")	
Copy from the temporary file.
   21   READ (T,11,END = 30) L,ALINE(1:L)	
        WRITE (F,12) ALINE(1:L)			
        GO TO 21		
Completed.
   30   CLOSE(T)		
        CLOSE(F)		
      END		

      PROGRAM CHOPPER
       CALL FILEHACK("foobar.txt",1,2)
      END
Task: Remove lines from a file





Java: import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class RemoveLines
{
	public static void main(String[] args)
	{
		
		String filename="foobar.txt";
		
		int startline=1;
		
		int numlines=2;
		
		RemoveLines now=new RemoveLines();
		now.delete(filename,startline,numlines);
	}
	void delete(String filename, int startline, int numlines)
	{
		try
		{
			BufferedReader br=new BufferedReader(new FileReader(filename));
			
			
			StringBuffer sb=new StringBuffer("");
			
			
			int linenumber=1;
			String line;
			
			while((line=br.readLine())!=null)
			{
				
				if(linenumber<startline||linenumber>=startline+numlines)
					sb.append(line+"\n");
				linenumber++;
			}
			if(startline+numlines>linenumber)
				System.out.println("End of file reached.");
			br.close();
			
			FileWriter fw=new FileWriter(new File(filename));
			
			fw.write(sb.toString());
			fw.close();
		}
		catch (Exception e)
		{
			System.out.println("Something went horribly wrong: "+e.getMessage());
		}
	}
}






Fortran:       SUBROUTINE CROAK(GASP)	
       CHARACTER*(*) GASP	
        WRITE (6,*) "Oh dear. ",GASP	
        STOP "++ungood."	
      END			

      SUBROUTINE FILEHACK(FNAME,IST,N)
       CHARACTER*(*) FNAME	
       INTEGER IST		
       INTEGER N		
       INTEGER ENUFF,L		
       PARAMETER (ENUFF = 66666)
       CHARACTER*(ENUFF) ALINE	
       INTEGER NREC		
       INTEGER F,T		
       PARAMETER (F=66,T=67)	
       LOGICAL EXIST
        IF (FNAME.EQ."") CALL CROAK("Blank file name
        IF (IST.LE.0)    CALL CROAK("First record must be positive
        IF (N.LE.0)      CALL CROAK("Remove count must be positive
        INQUIRE(FILE = FNAME, EXIST = EXIST)	
        IF (.NOT.EXIST) CALL CROAK("Can't find a file called "//FNAME)	
        OPEN (F,FILE=FNAME,STATUS="OLD",ACTION="READ",FORM="FORMATTED")	
        OPEN (T,STATUS="SCRATCH",FORM="FORMATTED")	
        NREC = 0		
Copy the desired records to a temporary file.
   10   READ (F,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11   FORMAT (Q,A)		
        IF (L.GT.ENUFF) CALL CROAK("Ow
        NREC = NREC + 1		
        IF (NREC.LT.IST .OR. NREC.GE.IST + N) WRITE (T,12) ALINE(1:L)	
   12   FORMAT (A)		
        GO TO 10		
Convert from input to output...
   20   IF (NREC.LT.IST + N) CALL CROAK("Insufficient records
        REWIND T		
        CLOSE(F)		
        OPEN (F,FILE=FNAME,FORM="FORMATTED",	
     1   ACTION="WRITE",STATUS="REPLACE")	
Copy from the temporary file.
   21   READ (T,11,END = 30) L,ALINE(1:L)	
        WRITE (F,12) ALINE(1:L)			
        GO TO 21		
Completed.
   30   CLOSE(T)		
        CLOSE(F)		
      END		

      PROGRAM CHOPPER
       CALL FILEHACK("foobar.txt",1,2)
      END
Task: Remove lines from a file







Python: 

import fileinput, sys

fname, start, count = sys.argv[1:4]
start, count = int(start), int(count)

for line in fileinput.input(fname, inplace=1, backup='.orig'):
    if start <= fileinput.lineno() < start + count:
        pass
    else:
        print line.rstrip("\n")
fileinput.close()




Fortran:       SUBROUTINE CROAK(GASP)	
       CHARACTER*(*) GASP	
        WRITE (6,*) "Oh dear. ",GASP	
        STOP "++ungood."	
      END			

      SUBROUTINE FILEHACK(FNAME,IST,N)
       CHARACTER*(*) FNAME	
       INTEGER IST		
       INTEGER N		
       INTEGER ENUFF,L		
       PARAMETER (ENUFF = 66666)
       CHARACTER*(ENUFF) ALINE	
       INTEGER NREC		
       INTEGER F,T		
       PARAMETER (F=66,T=67)	
       LOGICAL EXIST
        IF (FNAME.EQ."") CALL CROAK("Blank file name
        IF (IST.LE.0)    CALL CROAK("First record must be positive
        IF (N.LE.0)      CALL CROAK("Remove count must be positive
        INQUIRE(FILE = FNAME, EXIST = EXIST)	
        IF (.NOT.EXIST) CALL CROAK("Can't find a file called "//FNAME)	
        OPEN (F,FILE=FNAME,STATUS="OLD",ACTION="READ",FORM="FORMATTED")	
        OPEN (T,STATUS="SCRATCH",FORM="FORMATTED")	
        NREC = 0		
Copy the desired records to a temporary file.
   10   READ (F,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11   FORMAT (Q,A)		
        IF (L.GT.ENUFF) CALL CROAK("Ow
        NREC = NREC + 1		
        IF (NREC.LT.IST .OR. NREC.GE.IST + N) WRITE (T,12) ALINE(1:L)	
   12   FORMAT (A)		
        GO TO 10		
Convert from input to output...
   20   IF (NREC.LT.IST + N) CALL CROAK("Insufficient records
        REWIND T		
        CLOSE(F)		
        OPEN (F,FILE=FNAME,FORM="FORMATTED",	
     1   ACTION="WRITE",STATUS="REPLACE")	
Copy from the temporary file.
   21   READ (T,11,END = 30) L,ALINE(1:L)	
        WRITE (F,12) ALINE(1:L)			
        GO TO 21		
Completed.
   30   CLOSE(T)		
        CLOSE(F)		
      END		

      PROGRAM CHOPPER
       CALL FILEHACK("foobar.txt",1,2)
      END
Task: Remove lines from a file








VB: Option Explicit

Sub Main()
   
   RemoveLines "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 11, 5
   
   RemoveLines "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 8, 5
   
   RemoveLines "C:\Users\" & Environ("username") & "\Desktop\foobar.txt", 3, 5
End Sub

Private Sub RemoveLines(StrFile As String, StartLine As Long, NumberOfLines As Long)
Dim Nb As Integer, s As String, count As Long, out As String
   Nb = FreeFile
   Open StrFile For Input As #Nb
      While Not EOF(Nb)
         count = count + 1
         Line Input #Nb, s
         If count < StartLine Or count >= StartLine + NumberOfLines Then
            out = out & s & vbCrLf
         End If
      Wend
   Close #Nb
   If StartLine >= count Then
      MsgBox "The file contains only " & count & " lines"
   ElseIf StartLine + NumberOfLines > count Then
      MsgBox "You only can remove " & count - StartLine & " lines"
   Else
      Nb = FreeFile
      Open StrFile For Output As #Nb
         Print #Nb, out
      Close #Nb
   End If
End Sub



Fortran:       SUBROUTINE CROAK(GASP)	
       CHARACTER*(*) GASP	
        WRITE (6,*) "Oh dear. ",GASP	
        STOP "++ungood."	
      END			

      SUBROUTINE FILEHACK(FNAME,IST,N)
       CHARACTER*(*) FNAME	
       INTEGER IST		
       INTEGER N		
       INTEGER ENUFF,L		
       PARAMETER (ENUFF = 66666)
       CHARACTER*(ENUFF) ALINE	
       INTEGER NREC		
       INTEGER F,T		
       PARAMETER (F=66,T=67)	
       LOGICAL EXIST
        IF (FNAME.EQ."") CALL CROAK("Blank file name
        IF (IST.LE.0)    CALL CROAK("First record must be positive
        IF (N.LE.0)      CALL CROAK("Remove count must be positive
        INQUIRE(FILE = FNAME, EXIST = EXIST)	
        IF (.NOT.EXIST) CALL CROAK("Can't find a file called "//FNAME)	
        OPEN (F,FILE=FNAME,STATUS="OLD",ACTION="READ",FORM="FORMATTED")	
        OPEN (T,STATUS="SCRATCH",FORM="FORMATTED")	
        NREC = 0		
Copy the desired records to a temporary file.
   10   READ (F,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11   FORMAT (Q,A)		
        IF (L.GT.ENUFF) CALL CROAK("Ow
        NREC = NREC + 1		
        IF (NREC.LT.IST .OR. NREC.GE.IST + N) WRITE (T,12) ALINE(1:L)	
   12   FORMAT (A)		
        GO TO 10		
Convert from input to output...
   20   IF (NREC.LT.IST + N) CALL CROAK("Insufficient records
        REWIND T		
        CLOSE(F)		
        OPEN (F,FILE=FNAME,FORM="FORMATTED",	
     1   ACTION="WRITE",STATUS="REPLACE")	
Copy from the temporary file.
   21   READ (T,11,END = 30) L,ALINE(1:L)	
        WRITE (F,12) ALINE(1:L)			
        GO TO 21		
Completed.
   30   CLOSE(T)		
        CLOSE(F)		
      END		

      PROGRAM CHOPPER
       CALL FILEHACK("foobar.txt",1,2)
      END
Task: String case



C#: using System;

namespace StringCase
{
  class Program
  {
    public static void Main()
    {
      String input = scope .("alphaBETA");
      input.ToUpper();
      Console.WriteLine(input);
      input.ToLower();
      Console.WriteLine(input);
    }
  }
}









Ada: with Ada.Characters.Handling, Ada.Text_IO;
use  Ada.Characters.Handling, Ada.Text_IO;

procedure Upper_Case_String is
   S : constant String := "alphaBETA";
begin
   Put_Line (To_Upper (S));
   Put_Line (To_Lower (S));
end Upper_Case_String;