Group,

Some weeks back you helped me solve a formating issue with a text file that originates from a UNIX based program (see [https://www.daniweb.com/software-development/vbnet/threads/489626/remove-end-of-report-line-and-format-unix-text]).

While reviewing this newly formated data I saw that a character was place at the beginning of each page. Thus, I assume it does set the next page. However I'd like for you to look and confirm this. But more importantly, I need to know how to insert this character into my code. Because I am merging multiple reports together, I need to add this to the end of each report that is to be merged. I've attached a picture of this character for you to see.

My question is: What character is this, which VB code represents this character.

In advance, thanks for your help.

Don

The character appears to be Unicode &H2640

Referrencing from then link you posted, you can do it as you did to insert each and every line to the text file.
Place the codes to insert your characters at the end.

 For i As Integer = readtxt.GetLowerBound(0) To readtxt.GetUpperBound(0) - 2
            'Appending the line to the text file
            My.Computer.FileSystem.WriteAllText(RestranName, readtxt(i), True)
            If i < readtxt.GetUpperBound(0) - 2 Then
                'Appending a new line into the text file.
                My.Computer.FileSystem.WriteAllText(RestranName, vbCrLf, True)
            End If
        Next
        My.Computer.FileSystem.WriteAllText(RestranName, vbCrLf, True)
        My.Computer.FileSystem.WriteAllText(RestranName, "Your Charactors", True)
        Me.Cursor = Cursors.Default

Hope it can help you.

2.jpg Unicode character U+2640 called the female or venus sign. It will not do you any good in a notepad text file. Remember - this came from a unix program generated text and is probably a control character that is not understood by notepad and consequently the unix control character was mapped to a unicode character. If you want to keep it as is, don't delete the line it is in. You might as well insert a smily.

Minimalist, I understand Notepad doesn't recognize the character as anything. However this character is clearly needed, as I must delete the last few lines of "file1" to combine it with "file2". Therefore I need to add that UNIX character at the end of "file1" to ensure the combined file formats correctly.

I probably should show you what I've written to format the file so you can better understand:

                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)

If you have other ideas, I'm all ears!

As always, thanks for the help.

Don

Shark1, if I'm going to insert "Your Character", how is it I go about doing that? Minimalists tells me it is a UNIX character (Unicode character U+2640). Is there proper code to insert this like

Dim yourCharacter As (what?)
yourCharacter = 'Unicode character U+2640

Thanks....

Don

You can use the wide character method to translate the hex to a Char:

Dim pageCode As Char = Microsoft.VisualBasic.ChrW(&H2640)

pageCode can then be inserted into your text wherever you need it.

commented: thnx +5

Agreed with tinstaafl.
yous new character codes should be

My.Computer.FileSystem.WriteAllText(RestranName, Microsoft.VisualBasic.ChrW(&H2640), True)

Hope it can help you.

Gentleman, as always, Thank You!

I do need to ask: What does Me.Cursor = Cursors.Default do? Since I am having to merge as many as 7 files into 1, will I need to insert this code each time I insert the pageCode character?

Thanks group!

Don

I believe that's a hold over from the code he submitted to your previous question. Its purpose would be to signify to the user that the app is working by changing the cursor. Put Me.Cursor = Cursors.WaitCursor before you start processing the files then Me.Cursor = Cursors.Default when it is finished.

Agreed with tinstaafl.
This is a common practice to show the user that the process is in execution, don't confeuse. After completion it is ready to execute your next command.
You can also attach a visual style like progressbar, label control to show the current situation and percentage of work done and so, so ......

Oooooo.... I like this! Thank you again!!

This will prompt another question. But I'll write that in a new discussion.

Group, you're the greatest!

Don

Group,

I've added the character at the end of the text file. It is doing this correctly. However this may not be the whole issue. It seems that when I append the next file to it, this next file begins at the very end of last line. I need for it to begin on the next line after. You can see that "FP Calgary" is at the end of the 1st text file (See the attached example).

Can you suggest what I need to write in to make that happen?

As always, thanks for your assistance.

Don

Just make sure that any block of text you write is terminated with a vbCrLf.

Simply add a new line after addition of your charactor. A new line feeding is known to you from your previous posting.

My.Computer.FileSystem.WriteAllText(RestranName, vbCrLf & Microsoft.VisualBasic.ChrW(&H2640) & vbCrlf, True)

Hope it can help you.

Bingo.... that worked!

Thanks guys. You're the best!

Don

After looking over your post "Stopped Working" during routine I did some testing on the file that you posted there "20150228.txt". It appears that the symbol that you happened to see in Notepad, is actually a form feed (ASCII code 12 or 0C).

If using "ReadAllLines", one of the things used to split the lines is a line feed.

The symbol appears at the start of the line that contains "Page Number: 2", "Page Number: 3", etc. If you use a hex editor/viewer to view the file "20150228.txt", you will see the following: 0a0c 466f 7572 or 0a 0c 46 6f 75 72.
If you look up the ASCII codes,
0a = 0A = a = A = line feed/new line
0c = 0C = c = C = form feed/new page
46 = F
6f = o
75 = u
72 = r

Since, "ReadAllLine" split using the line feed (0A), it is no longer present. However, the form feed (0C) is still present, and is now at the beginning of the next line.

Here is the code that can be used to verify this:

    Public Sub ConvertTextToASCIICodes(ByVal inputFilename As String, ByVal inputFileEncoding As Encoding, ByVal outputFilename As String, ByVal outputFileEncoding As Encoding)

        'delete previous output file
        If System.IO.File.Exists(outputFilename) Then
            System.IO.File.Delete(outputFilename)
        End If

        'read input file data into a string array
        Dim fileDataArr() As String = File.ReadAllLines(inputFilename, inputFileEncoding)

        For Each line In fileDataArr
            'Desired symbol (form feed - ASCII code: 0C) 
            'appears before the hotel name.
            'The symbol is actually after the line feed, but 
            'ReadAllLines splits on the line feed, so the form feed
            'ends up at the beginning of the next element.

            If (line.Contains("Four Points Eastham") Or line.Contains("FP Calgary")) Then
                Debug.WriteLine("'" & line & "'")

                Dim asciiArr As Byte() = Encoding.ASCII.GetBytes(line)

                Dim decimalStr As String = String.Empty
                Dim hexStr As String = String.Empty

                'convert to ASCII values
                For i As Integer = 0 To asciiArr.Length - 1
                    hexStr += asciiArr(i).ToString("X2") & " "
                    decimalStr += asciiArr(i).ToString("D2") & " "
                Next

                Debug.WriteLine("Hex: " & hexStr)
                Debug.WriteLine("Dec: " & decimalStr)
                Debug.WriteLine("")

                Dim outputStr = line & System.Environment.NewLine
                outputStr += hexStr & System.Environment.NewLine
                outputStr += decimalStr & System.Environment.NewLine & System.Environment.NewLine

                'save output
                File.AppendAllText(outputFilename, outputStr, outputFileEncoding)
            End If
        Next
    End Sub

Usage:

ConvertTextToASCIICodes("C:\Restran Conversion\1540\20150228.txt", Encoding.ASCII, "C:\Restran Conversion\Output.txt", Encoding.ASCII)

Resource:
How to get ASCII values of a string in VB.net

Here is the output of running the above code on file "20150228.txt" from the post mentioned above.

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.