C# Encoding a text string with line breaks

前端 未结 4 1349
暖寄归人
暖寄归人 2021-02-01 12:46

in C# I have a string I am writing to the outputstream of the response. After I save this document and open it in Notepad++ or WordPad I get nicely formatted line breaks where

相关标签:
4条回答
  • 2021-02-01 13:02

    Use Environment.NewLine for line breaks.

    0 讨论(0)
  • 2021-02-01 13:02

    Try this :

    string myStr = ...
    myStr = myStr.Replace("\n", Environment.NewLine)
    
    0 讨论(0)
  • 2021-02-01 13:03

    Try \n\n , it will work! :)

    public async Task AjudaAsync(IDialogContext context, LuisResult result){
    await context.PostAsync("How can I help you? \n\n 1.To Schedule \n\n 2.Consult");
    context.Wait(MessageReceived);
    }
    
    0 讨论(0)
  • 2021-02-01 13:04

    Yes - it means you're using \n as the line break instead of \r\n. Notepad only understands the latter.

    (Note that Environment.NewLine suggested by others is fine if you want the platform default - but if you're serving from Mono and definitely want \r\n, you should specify it explicitly.)

    0 讨论(0)
提交回复
热议问题