Question

I'm writing to a file as shown below. I am ONE HUNDRED % SURE there are no line breaks in the variables being written to the file. However, at an arbitrary character count in every line printed to Notepad of applicable length, a line break is created. However, pressing delete at the end of the file (even holding delete) to get rid of any non-printing character such as a line break has no effect. Pressing backspace before the first character of any line affected by this deletes the last character on the previous line, but does get rid of the line break. Writing after the last character is immediately moved to the next line. I have tested on a new line, holding a character just to see if i can get past the point at which the word wrap begins. I can, but not where the c# has written to. I have tried TYPE KEYWORDS.LOG in the command, and it does not print the line breaks, so I do not (think) it will effect my reading the file by line later. But is this a glitch in Notepad? In C#? In IO.StreamWriter? In my code? (I don't think so?) Is it simply a property I am unaware of?

OBVIOUSLY, WORD WRAP IS NOT ON. BUT THANKS. . .

resizing the window does not wrap the text, or change the effects I have described at all.

// OPEN STREAM TO KEYWORDS.LOG
StreamWriter fileWrite = new StreamWriter("KEYWORDS.LOG");

for (int i=0;i<Referrals.Count();i++)
{
    // FIRST THE URL
    Console.Write("\n\n{0}\n-", Referrals[i].URL);

    // NOW TO THE FILE!
    fileWrite.Write("{0}@", Referrals[i].URL);


    var SortedKeys = from k in Referrals[i].Keywords.Keys orderby Referrals[i].Keywords[k] descending select k;
    foreach (string Phrase in SortedKeys)
    {
    // NOW TO THE CONSOLE
    Console.Write("\t({0}) {1}\n", Referrals[i].Keywords[Phrase], Phrase);

    // NOW TO THE FILE!
    fileWrite.Write("##{0}##{1}", Referrals[i].Keywords[Phrase], Phrase);
    }

    // LINE BREAK FOR FILE!
    fileWrite.WriteLine("");

}


    // CLOSE FILE STREAM
    fileWrite.Close();
Was it helpful?

Solution

It probably isn't arbitrary, you just haven't seen the reason.

Have a look at C# TextWriter inserting line break every 1024 characters

The max length is 1024.

Paste some example text if you can ;D

OTHER TIPS

This is definitely not a word wrap issue. I encountered this issue in notepad using a previous version of windows (XP, I think) and the limit was 4096 characters. Today I tried it in windows 7's notepad and the limit is 1024 characters. Several other text editors I have tried impose a "characters per line" limit that is often undocumented. I rarely encounter a situation where I need more than a few hundred characters per line, but I see no reason to impose a limit.

I first encountered the problem when creating ASCII stereograms. I wanted one that was big enough to print on a poster and I was looking at it in notepad. As soon as I generated one over 4096 characters wide, every line was wrapped. It looked awful.

These text viewers are not actually inserting any line breaks into the text. They are just altering the way they display the text. That is why you can delete the last character of the "line" when your cursor is at the beginning of the next "line". I put "line" in quotes because it is not truly a line. You are actually deleting text somewhere in the middle of the real line of text. Assuming the text editor is well-behaved, when you save the file, it will still have the long line. If you later view the text in a viewer capable of displaying long enough lines, it should display correctly.

Is it possible you you have "Word wrap" on in notepad? Sorry if this seems like an obvious question.

Errr... Doublecheck "Format" - "Word Wrap" in Notepad.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top