title: Find and replace NUL character using VBScript
body: <p>I have a text file which contains NUL characters in random rows. I want to find first NUL character and delete entire row from that NUL character as in below:</p>
  
  <p>Input:</p>
  
  <pre class="lang-none prettyprint-override"><code>1 2 3 4 20170821NUL20170821NULNULNULNUL 123 NULNULNUL
  1 2 3 4 20170821 20170821 6 7 10 123 10 11 13
  1 2 3 4 20170821NUL20170821NULNULNULNUL 123 NULNULNUL
  1 2 3 4 20170821NUL20170821NULNULNULNUL 123 NULNULNUL
  </code></pre>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>1 2 3 4 20170821
  1 2 3 4 20170821 20170821 6 7 10 123 10 11 13
  1 2 3 4 20170821
  1 2 3 4 20170821
  </code></pre>
  
  <p>I have the following to read text file data to a variable and loop through the data and replace NUL:</p>
  
  <pre><code>sInfile = WScript.Arguments(1)
  
  'Create file system object
  Set oFSO = CreateObject("Scripting.FileSystemObject")
  Set oFS = oFSO.OpenTextFile(sInfile)
  sData = oFS.ReadAll
  oFS.Close
  Set oFS = Nothing
  
  MsgBox("File Read Completed")
  
  'Remove Rest of the line from NULL
  Do While InStr(sData, "\00.*") &gt; 0
      sData = Replace(sData, "\00.*", "")
  Loop
  
  'Cleanup and end
  Set oFS = Nothing
  WScript.Quit
  </code></pre>
  
  <p>The script went passed without any errors but I can't see any changes to the data.</p>
  
  <p><strong>EDIT 1:</strong>
  Updated code:</p>
  
  <pre><code>Const ForReading = 1
  Const ForWriting = 2
  Const TriStateUseDefault = -2
  
  If (WScript.Arguments.Count &gt; 0) Then
      sInfile = WScript.Arguments(0)
  Else
      WScript.Echo "No filename specified."
      WScript.Quit
  End If
  If (WScript.Arguments.Count &gt; 1) Then
      sOutfile = WScript.Arguments(1)
  Else
      sOutfile = sInfile
  End If
  
  'Get the text file from cmd file
  sInfile = Wscript.Arguments(1)
  ' Create file system object
  Set oFSO = CreateObject("Scripting.FileSystemObject")
  Set oFS = oFSO.OpenTextFile(sInfile)
  sData = oFS.ReadAll
  oFS.Close
  Set oFS = Nothing
  
  ' Remove Rest of the line from NULL
  Set re = New RegExp
  re.Pattern = Chr(0) &amp; ".*"
  re.Global  = True
  sData = re.Replace(sData, "")
  
  Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)
  oOutfile.Write(sData)
  oOutfile.Close
  Set oOutfile = Nothing
  
  ' Cleanup and end
  Set oFS = Nothing
  WScript.Quit
  </code></pre>
  
  <p>Here is the sample input I am giving:</p>
  
  <p><a href="https://i.stack.imgur.com/Fuend.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fuend.png" alt="enter image description here"></a></p>
  
  <p>I would like to see the output as below:</p>
  
  <p><a href="https://i.stack.imgur.com/nDyXn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nDyXn.png" alt="enter image description here"></a></p>
  
  <p>But I got the below output:</p>
  
  <pre>
  ੊ਊਊਊਊਊਊਊਊਊਊ
  </pre>
  
  <p><strong>EDIT 2:</strong>
  I am not aware of hex editors. Here is the sample input of HextDump:</p>
  
  <pre><code>FF FE 4A 00 42 00 43 00 09 00 31 00 32 00 33 00 34 00 38 00 36 00 37 00 38 
  00 09 00 38 00 37 00 09 00 30 00 09 00 30 00 09 00 31 00 32 00 33 00 09 00 
  32 00 30 00 31 00 37 00 09 00 31 00 32 00 33 00 34 00 09 00 31 00 33 00 34 
  00 32 00 30 00 09 00 32 00 30 00 31 00 37 00 30 00 38 00 30 00 39 00 09 00 
  35 00 31 00 30 00 33 00 09 00 09 00 09 00 09 00 33 00 34 00 31 00 34 00 38 
  00 38 00 09 00 32 00 09 00 32 00 30 00 31 00 37 00 09 00 38 00 09 00 31 00 
  09 00 37 00 09 00 2D 00 32 00 36 00 34 00 30 00 09 00 2D 00 33 00 39 00 33 
  00 2E 00 31 00 36 00 31 00 33 00 37 00 35 00 09 00 2D 00 33 00 33 00 32 00 
  2E 00 34 00 36 00 38 00 35 00 37 00 39 00 09 00 41 00 30 00 31 00 31 00 32 
  00 35 00 38 00 39 00 2F 00 33 00 34 00 31 00 34 00 38 00 38 00 2F 00 09 00 
  09 00 09 00 09 00 09 00 09 00 09 00 09 00 32 00 09 00 09 00 09 00 32 00 31 
  00 37 00 38 00 31 00 09 00 58 00 59 00 5A 00 09 00 58 00 59 00 5A 00 09 00 
  58 00 59 00 5A 00 09 00 31 00 32 00 33 00 09 00 31 00 32 00 33 00 09 00 2D 
  00 32 00 36 00 34 00 09 00 58 00 59 00 5A 00 09 00 31 00 09 00 31 00 09 00 
  31 00 32 00 33 00 09 00 09 00 09 00 32 00 31 00 37 00 38 00 32 00 31 00 0D 
  00 0A 00 41 00 42 00 43 00 09 00 31 00 32 00 33 00 34 00 38 00 36 00 37 00
  </code></pre>
  
  <p>and the HexDump of output which I got <code>FF FE 4A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A</code></p>