special line feed character appear in notepad - windows form - c sharp

  • Thread starter solo h via DotNetMonster.com
  • Start date
S

solo h via DotNetMonster.com

hello members,
i m using windows form c#
using follwoing code

StreamWriter sw = new StreamWriter(new FileStream(@"c:\anyTextFile.txt",
FileMode.Append));
sw.WriteLine("this is test text \n now from here is next line");
sw.Flush();
sw.Close();

i m trying to write a simple text file, when i open that file in any text pad
it shows data as follow

//**
this is test text
now from here is next line
**//

but when i open that file in windows notepad it shows data as follow

//**
this is test text ? now from here is next line
**//

that is theres sum square box inplace of linefeed,
i want if i open same file in notepad it shows same as of textpad, why it is
not showing, how to overcum that .

regards..
 
M

Morten Wennevik

Hi Solo H,

In Windows, \r\n is used for linebreaks, not just \n. Use \r\n or Environment.NewLine.

Some programs may accept \n as linebreak but don't count on it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top