Solved open file - remove all text between 2 symbols

Posted on 2011-05-12
Last Modified: 2012-06-27
I want to open this file and remove the text between the --<<< symbols.  I want to then close the file so I can run it.

USE [master]
CREATE DATABASE [keypatrollerlocal] ON  PRIMARY
( NAME = N'keypatrollerlocal', FILENAME = N'C:\KeyPatroller\SQL\keypatrollerlocal.mdf' , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
( NAME = N'keypatrollerlocal_log', FILENAME = N'C:\KeyPatroller\SQL\keypatrollerlocal_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
Question by:MBoy
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Are those symbols always on their own line?...or can they be mixed in with other stuff?
    LVL 3

    Author Comment

    I have them on their own lines.  In my script there are about 30 lines between the symbols.
    LVL 85

    Accepted Solution

    Here's one way:
    Dim FileName As String = "C:\Users\Mike\Documents\SomeFile.txt"
            Dim Marker As String = "--<<<"
            Dim InMarkedArea As Boolean = False
            Dim Lines As New List(Of String)
            Dim index As Integer = 0
            While index < Lines.Count
                If Lines(index) = Marker Then
                    InMarkedArea = Not InMarkedArea
                    index = index + 1
                    If InMarkedArea Then
                        index = index + 1
                    End If
                End If
            End While
            System.IO.File.WriteAllLines(FileName, Lines.ToArray)

    Open in new window


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    scoresAverage challenge 8 58
    Fibonacci challenge 11 61
    count8 challlenge 13 68
    drawing animated level bar based on numbers 3 44
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    This is about my first experience with programming Arduino.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now