'remove 1st column and its trailing white space Sub StepOne() Dim strCurrent As String = "" Dim strRoot As String = "" Try strCurrent = Directory.GetCurrentDirectory() 'strRoot = Directory.GetDirectoryRoot(strCurrent) 'strRoot = Directory.GetDirectoryRoot("\") Catch E As Exception 'Console.WriteLine("Error determining root directory") MessageBox.Show(E.Message) End Try 'read hostsfile.txt Dim strfileName As String strfileName = strCurrent & "\" & "hotlist.txt" Replace(strfileName, "\n1 ", "\n") End Sub 'GENERIC REGEX SEARCH & REPLACE. Use Regular Expressions to search/replace within file Function Replace(ByRef file As String, ByRef searchFor As String, ByRef replaceWith As String) As Boolean 'function used during Validation 'use Regular Expressions to search for and replace user defined variables Try Dim reader As New StreamReader(file) 'get a StreamReader for reading the file Dim contents As String = reader.ReadToEnd() 'read the entire file at once reader.Close() reader.Dispose() 'close up and dispose 'use regular expressions to search and replace text contents = Regex.Replace(contents, searchFor, replaceWith, RegexOptions.IgnoreCase Or RegexOptions.Compiled) Dim writer As New StreamWriter(file) 'get a StreamWriter for writing the new text to the file writer.Write(contents) 'write the contents writer.Close() writer.Dispose() 'close up and dispose Return True 'return successful Catch generatedExceptionName As Exception MessageBox.Show(generatedExceptionName.Message) Return False End Try End Function
|New to Angular (read tutorial) - How do I bind to this table?||11||35|
|Help with creating multiple xml files from one xml file using VB.NET||6||24|
|How to LOAD up a .NET Framework website with data?||2||12|
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
20 Experts available now in Live!