Replace Line Breaks in a String C#

后端 未结 17 1176
失恋的感觉
失恋的感觉 2020-11-22 11:16

How can I replace Line Breaks within a string in C#?

17条回答
  •  鱼传尺愫
    2020-11-22 11:53

    Use replace with Environment.NewLine

    myString = myString.Replace(System.Environment.NewLine, "replacement text"); //add a line terminating ;
    

    As mentioned in other posts, if the string comes from another environment (OS) then you'd need to replace that particular environments implementation of new line control characters.

提交回复
热议问题