Padding with NULL char
-
Hello everybody. I have a file that is spaced with NULL instead of standard spaces. LIKE SO... COMPANYNAME C(NULL)O(NULL)M(NULL)P(NULL)A(NULL)N(NULL)Y(NULL)N(NULL)A(NULL)M(NULL)E(NULL) I'm trying to make a utility that will remove or add the NULL spacing. First I started on the add function. Here's what I have
Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click Dim FileName As String = "" With dlgOpenFile .InitialDirectory = "C:\Stuff\Office2K3.SP2" .Filter = "All Files|*.*" End With If (dlgOpenFile.ShowDialog = Windows.Forms.DialogResult.OK) Then FileName = dlgOpenFile.FileName 'Dim sr As System.IO.StreamReader = Nothing 'sr = New System.IO.StreamReader(FileName) 'CurrentFileContents = sr.ReadToEnd Dim fs As System.IO.FileStream = New System.IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read) Dim strLength As Integer = Convert.ToInt32(fs.Length) Dim fileData As Byte() = New Byte(strLength) {} fs.Read(fileData, 0, strLength) fs.Flush() fs.Close() For Each x As Byte In fileData txtOut.Text &= Convert.ToChar(x) & Chr(&H0) Next x 'For Each x As Char In CurrentFileContents 'txtOut.Text &= x & vbNullChar 'Next x 'sr.Close() End If End Sub Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click If (CurrentFileContents = "") Then btnOpenFile_Click(sender, e) End If Dim null As String = vbNullChar Dim newFile As String = "" For Each x As Char In CurrentFileContents newFile &= x & CStr(vbNullChar) Next x txtOut.Text = newFile End Sub
I've tried 2 different ways. I tried using a streamreader and dumping the file into a string. Then iterate with a for each loop and append a NULL char after each value. This results in a string with 1 Char in it, the first one "C". If I remove the NULL char, the string will be complete. The other method was using a byte array. This resulted in a dump but without the NULL bytes. I've researched and there is alot of "NULL removal" or "MYSQL and NULL in DateField" but I see nothing on NULL paddi
-
Hello everybody. I have a file that is spaced with NULL instead of standard spaces. LIKE SO... COMPANYNAME C(NULL)O(NULL)M(NULL)P(NULL)A(NULL)N(NULL)Y(NULL)N(NULL)A(NULL)M(NULL)E(NULL) I'm trying to make a utility that will remove or add the NULL spacing. First I started on the add function. Here's what I have
Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click Dim FileName As String = "" With dlgOpenFile .InitialDirectory = "C:\Stuff\Office2K3.SP2" .Filter = "All Files|*.*" End With If (dlgOpenFile.ShowDialog = Windows.Forms.DialogResult.OK) Then FileName = dlgOpenFile.FileName 'Dim sr As System.IO.StreamReader = Nothing 'sr = New System.IO.StreamReader(FileName) 'CurrentFileContents = sr.ReadToEnd Dim fs As System.IO.FileStream = New System.IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read) Dim strLength As Integer = Convert.ToInt32(fs.Length) Dim fileData As Byte() = New Byte(strLength) {} fs.Read(fileData, 0, strLength) fs.Flush() fs.Close() For Each x As Byte In fileData txtOut.Text &= Convert.ToChar(x) & Chr(&H0) Next x 'For Each x As Char In CurrentFileContents 'txtOut.Text &= x & vbNullChar 'Next x 'sr.Close() End If End Sub Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click If (CurrentFileContents = "") Then btnOpenFile_Click(sender, e) End If Dim null As String = vbNullChar Dim newFile As String = "" For Each x As Char In CurrentFileContents newFile &= x & CStr(vbNullChar) Next x txtOut.Text = newFile End Sub
I've tried 2 different ways. I tried using a streamreader and dumping the file into a string. Then iterate with a for each loop and append a NULL char after each value. This results in a string with 1 Char in it, the first one "C". If I remove the NULL char, the string will be complete. The other method was using a byte array. This resulted in a dump but without the NULL bytes. I've researched and there is alot of "NULL removal" or "MYSQL and NULL in DateField" but I see nothing on NULL paddi
-
Hello everybody. I have a file that is spaced with NULL instead of standard spaces. LIKE SO... COMPANYNAME C(NULL)O(NULL)M(NULL)P(NULL)A(NULL)N(NULL)Y(NULL)N(NULL)A(NULL)M(NULL)E(NULL) I'm trying to make a utility that will remove or add the NULL spacing. First I started on the add function. Here's what I have
Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click Dim FileName As String = "" With dlgOpenFile .InitialDirectory = "C:\Stuff\Office2K3.SP2" .Filter = "All Files|*.*" End With If (dlgOpenFile.ShowDialog = Windows.Forms.DialogResult.OK) Then FileName = dlgOpenFile.FileName 'Dim sr As System.IO.StreamReader = Nothing 'sr = New System.IO.StreamReader(FileName) 'CurrentFileContents = sr.ReadToEnd Dim fs As System.IO.FileStream = New System.IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read) Dim strLength As Integer = Convert.ToInt32(fs.Length) Dim fileData As Byte() = New Byte(strLength) {} fs.Read(fileData, 0, strLength) fs.Flush() fs.Close() For Each x As Byte In fileData txtOut.Text &= Convert.ToChar(x) & Chr(&H0) Next x 'For Each x As Char In CurrentFileContents 'txtOut.Text &= x & vbNullChar 'Next x 'sr.Close() End If End Sub Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click If (CurrentFileContents = "") Then btnOpenFile_Click(sender, e) End If Dim null As String = vbNullChar Dim newFile As String = "" For Each x As Char In CurrentFileContents newFile &= x & CStr(vbNullChar) Next x txtOut.Text = newFile End Sub
I've tried 2 different ways. I tried using a streamreader and dumping the file into a string. Then iterate with a for each loop and append a NULL char after each value. This results in a string with 1 Char in it, the first one "C". If I remove the NULL char, the string will be complete. The other method was using a byte array. This resulted in a dump but without the NULL bytes. I've researched and there is alot of "NULL removal" or "MYSQL and NULL in DateField" but I see nothing on NULL paddi
The file is using a different encoding than ASCII, most likely Unicode. Change the StreamReader line to this to have it try and determine the encoding automatically:
Dim sr As New StreamReader(filename**, True**)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008