Need Help Opening/Searching File and Inserting a Character
Posted on 2006-11-11
Basically, I'm writing one big program to assist me with a game server I run to combine its ban key records. The data is stored in a text file as follows:
Profile Name, CD Key Hash, # of Bans, Ban End Date
As players are banned, this banned.txt file is appended. Unfortunately when you open up this ban file, the records don't space out nicely. That is, all records are on the same line. My goal is to get them all on their own line in the above format.
Each ban record will either end in two dashes ("--") or with date and time information in the following format: YYYY-MM-DD HH:NN:SS (n=minutes). I need to search for these instances and insert an ENTER character, thus putting all records on their own line. That is my question in this post.
I've retrieved the following code off experts-exchange.com, which opens up a text file from the open file dialog box and places its contents into a Rich Text Box. When I do this, again, my results displayed are jumbled, and are all on the same line. Inside the TRY block, the code RichTextBox1.Text = sr.ReadToEnd() places the text from the text file opened into the rich text box.
EVENTUALLY, I plan on using a menu option to display a new form that will prompt the user to browse for multiple text files, appending each file into one master file and then filtering the results based on the CD Key Hash. The program will also eventually link to a database and its form will allow the user to navigate through all the ban records, displaying a large multiline text box for the user to write notes on each record.
Again, at this time, I only need help with inserting ENTER characters (or you might call them carriage returns) after certain strings are found. Please adapt to the following code:
Private FileName As String
Dim sr As StreamReader
Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click
Dim supportPath As String = "C:\Temp\"
ofdBanList.Title = "Please select a file to open"
ofdBanList.InitialDirectory = supportPath
.Filter = "Text Files (*.txt)|*.txt"
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
FileName = .FileName
sr = New StreamReader(.OpenFile)
'Displays the file in a RICH TEXT BOX
RichTextBox1.Text = sr.ReadToEnd()
Catch es As Exception
If Not (sr Is Nothing) Then
I'm using VB .NET 2005