[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB.net open file - remove all text between 2 symbols

Posted on 2011-05-12
3
Medium Priority
?
327 Views
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]
GO
CREATE DATABASE [keypatrollerlocal] ON  PRIMARY
( NAME = N'keypatrollerlocal', FILENAME = N'C:\KeyPatroller\SQL\keypatrollerlocal.mdf' , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON
( NAME = N'keypatrollerlocal_log', FILENAME = N'C:\KeyPatroller\SQL\keypatrollerlocal_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
--<<<
0
Comment
Question by:MBoy
  • 2
3 Comments
 
LVL 86

Expert Comment

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

Author Comment

by:MBoy
ID: 35747271
I have them on their own lines.  In my script there are about 30 lines between the symbols.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 35747474
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)
        Lines.AddRange(System.IO.File.ReadAllLines(FileName))
        Dim index As Integer = 0
        While index < Lines.Count
            If Lines(index) = Marker Then
                InMarkedArea = Not InMarkedArea
                index = index + 1
            Else
                If InMarkedArea Then
                    Lines.RemoveAt(index)
                Else
                    index = index + 1
                End If
            End If
        End While
        System.IO.File.WriteAllLines(FileName, Lines.ToArray)

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Loops Section Overview

834 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