Inserting an 'ENTER' into a textfile

Gluttard

Active member
Joined
Jan 9, 2008
Messages
44
Programming Experience
Beginner
Hello, I made a decoder that makes a long messy log into manageably chunks.
All I need to do is figure out how to skip a line in the textfile, so I'll write 50 characters to the textfile, insert an 'ENTER', then write 50 more...

I tried to use Chr(12) but it came up as a little black box. (That is the enter key's equivalant, right?)

Thanks
 
Environment.NewLine or ControlChars.NewLine

---Edit---
Now that I'm thinking Chr(12) is a page break and Chr(10) & Chr(13) is a hard 'Enter'. Notepad doesn't know what a page break is so it's giving you the box. Try opening it in Word and you'll see the break. The options listed above are still better options regardless.
 
Last edited:
PHP:
        My.Computer.FileSystem.WriteAllText("C:\my.txt", "THis is an ETNERR", True)
        My.Computer.FileSystem.WriteAllText("C:\my.txt", Chr(13), True)
        My.Computer.FileSystem.WriteAllText("C:\my.txt", "THis is an ETNERR", True)

Say I have that, with Chr(10) and Chr(13) it gives me the unrecognizable character. Any help?

whoops there are a bunch of typos in the Strings of that code. Ah well.

Hello, Thanks for the help MattP, I did some indepth research and ended up finding out how.

All you really need to do is write 'vbCrLf' to the file. That's a carriage return. Joyous.
 
PHP:
        My.Computer.FileSystem.WriteAllText("C:\my.txt", "THis is an ETNERR", True)
        My.Computer.FileSystem.WriteAllText("C:\my.txt", Chr(13), True)
        My.Computer.FileSystem.WriteAllText("C:\my.txt", "THis is an ETNERR", True)

Say I have that, with Chr(10) and Chr(13) it gives me the unrecognizable character. Any help?

whoops there are a bunch of typos in the Strings of that code. Ah well.

Hello, Thanks for the help MattP, I did some indepth research and ended up finding out how.

All you really need to do is write 'vbCrLf' to the file. That's a carriage return. Joyous.

vbCrLf, vbCr and vbLf may not be supported in future versions of .Net and if you run vbCrLf on a Linux machine (using the Mono framework) it'll crash. If you use Environment.NewLine it'll work with all future versions of .Net and will provide the new line characters for different platforms.

Just a suggestion
 
Is there any difference between using Environment.NewLine and ControlChars.CrLf?
They both return the same string, so does vbNewLine.

According to documentation Environment.NewLine should return a different string on Unix, but .Net Framework only runs on Windows platform yet. There is a Mono initiative that has written a comparable .Net framework library for Unix platforms, but I don't know if they have done certain conversions for these constants.

Also, some prefer to not import the Microsoft.VisualBasic namespace, which would lead to easier access to the common framework System.Environment than the Visual Basic runtime Microsoft.VisualBasic.ControlChars. Especially programmers switching/converting between several .Net languages tend to avoid VB specifics. MS recommends VB programmers to use the VB runtime library and VB specific functionality that may be available.
 
Back
Top