Question

I have a text file that, when I open it in Notepad, shows the form feed character (byte 12). I want to show this character in my richtextbox but no matter which encoding I use when I read the text file it won't show. When I enter the character myself it shows. When I do myRTB.Text = "♀" it shows, but when I do

myRTB.Text = File.ReadAllText(myFileName.txt);

it doesn't show. I've also tried using the readers in the Encoding class to no avail.

How can I show the form feed character in my rtb?

Was it helpful?

Solution 3

Thanks for the help @jmcilhinney and @Damith. I ended up cheating the system by doing a dirty. I saw that myRTB was replacing the form feed char with \page in the RTF, but when I typed the form feed char myself it put \u9792. Therefore I went with the hack:

myRTB.Rtf = myRTB.Rtf.Replace("\\page", "\\u9792");

If you have something less hackish that I can get working please let me know.

OTHER TIPS

Firstly, a line feed has a value of 13. If you have characters with the value 12 in there then they are not line feeds.

As for your issue, ReadAllLines reads the lines of a file into a String array, thus stripping out all the line breaks. You might do as Damith suggests and call ReadAllText, which reads the file contents as a single String, and assign the result to the Text property or else call ReadAllLines and assign the result to the Lines property. Better to call LoadFile on the RichTextBox itself though.

try with ReadAllText

myRTB.Text = File.ReadAllText(myFileName.txt, Encoding.Unicode);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top