Hi group,

I'm using VB.net to convert an output file (text) from a Linux based program into a file that will easily read in Notepad. I found some code in VB.net to do this conversion for UNIX that works "OK" (meaning fair but not perfect). It looks like this:

txtLine = My.Computer.FileSystem.ReadAllText(RestranName)
' This begins to add the carriage returns in the appropriate places

txtLine = Replace(txtLine, vbLf, vbCrLf)
txtLine = Replace(txtLine, vbCr & vbCr, vbCr)
txtLine = Replace(txtLine, """", "")
' This writes the line to the file
My.Computer.FileSystem.WriteAllText(fileSave, txtLine, False)

The only issue (it's minor) is that it is adding a "ChrW(H2640)" character at the begining of each new page.

My question is: Would you know a better way to correct this so that it is formatted correctly and without the additional character?

In advance, thanks for your help.

Don

Dani AI

Generated

Short answer: the LF→CRLF conversion you already have is fine; that extra glyph usually comes from either an embedded page-break control (form feed, ASCII 12) or an encoding/BOM mismatch that makes a byte sequence render as an odd Unicode character. ’s Notepad++ tip is useful for quick checks, but it helps to identify the exact codepoint before stripping anything.

To diagnose: open the file in Notepad++ and enable View → Show Symbol → Show All Characters, or use a hex-view/Hex-Editor plugin to see the bytes at each page break. Alternatively, run a tiny check in VB to print non-printing codepoints near the problem location so you know the numeric value to remove:

Dim txt = IO.File.ReadAllText(RestranName, System.Text.Encoding.Default)
For i = 0 To txt.Length - 1
    Dim v = AscW(txt(i))
    If v < 32 Or v = 127 Or v > 65500 Then Debug.WriteLine("pos " & i & " -> " & v)
Next

Fixes (pick one after you confirm the codepoint): if it’s form-feed remove it with text = text.Replace(ChrW(12), ""); if it’s a specific Unicode codepoint remove that one (e.g. ChrW(&H2640) only after confirming). Prefer reading with encoding detection to avoid BOM surprises:

Using sr As New IO.StreamReader(RestranName, True)
    Dim raw = sr.ReadToEnd()
    raw = raw.Replace(ChrW(12), "")   ' or replace the confirmed codepoint
    IO.File.WriteAllText(fileSave, raw, System.Text.Encoding.UTF8)
End Using

Caution: back up originals, test with Notepad++ after each change, and if page breaks are meaningful, replace them with a visible marker instead of deleting. Mention — identifying the exact numeric value is the key step before removing characters.

There are simple tools to do this without having to resort to VB. Look at notepad++. It can easily convert Unix/Linux text files to Windows ones (converting the LF in the *nix files to CRLF for Windows), and vice-versa.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.