替换字符串中的换行符 C# [英] Replace Line Breaks in a String C#

查看:37
本文介绍了替换字符串中的换行符 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 C# 中替换字符串中的换行符?

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

推荐答案

Use replace with Environment.NewLine

Use replace with Environment.NewLine

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

如其他帖子所述,如果字符串来自另一个环境 (OS),那么您需要替换 新的行控制字符.

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.

这篇关于替换字符串中的换行符 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆