Hack Forums
[.NET] Write in textfile & recognize new lines from RichTextBox - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Write in textfile & recognize new lines from RichTextBox (/showthread.php?tid=5728485)



Write in textfile & recognize new lines from RichTextBox - BapeZ - Oct 1, 2017

Hey,
i want my program to write text from a RichTextBox to the hosts.-file to block some sites. My problem is now that my code doesn't recognize a new line I have made in the RichTextBox. It writes the text in the hosts.-file like this:
"127.0.0.1 www.virustotal.com127.0.0.1 www.eset.com127.0.0.1 www.avast.com"

Code
Dim Hosts As String = Environment.SystemDirectory & "\drivers\etc\hosts"
                        Dim sr As New StreamReader(Hosts)
                    Dim input As String = sr.ReadToEnd()
                        sr.Close()
                        Dim output As String = input & vbNewLine & blockedwww
                    output.Replace(vbLf, vbNewLine)
                        Dim sw As New StreamWriter(Hosts)
                        sw.Write(output)
                        sw.Close()

blockedwww = RichTextBox.Text
If you know how I can fix that, I really appreciate your help!

Best regards


* - dicktembe - Oct 1, 2017

Read this: https://www.dotnetperls.com/for-vbnet
Should be fairly easy to understand how to use a for next statement.


* - Barret - Oct 1, 2017

You are using the unix format of newline (lf), windows has crlf's, to be safe use Environment.Newline