Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Padding with NULL char

Padding with NULL char

Scheduled Pinned Locked Moved Visual Basic
mysqldata-structurestools
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    akuma6099
    wrote on last edited by
    #1

    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

    C D 2 Replies Last reply
    0
    • A akuma6099

      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

      C Offline
      C Offline
      Chinners
      wrote on last edited by
      #2

      It looks like you have a unicode file, not an ascii one... I am sure, armed with this knowledge, google will help you out more than I can ;)

      1 Reply Last reply
      0
      • A akuma6099

        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

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups