且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从C#中的字符串末尾删除回车符和换行符

更新时间:2023-12-03 19:47:10

这将从s的末尾修剪掉回车符和换行符的任何组合:

This will trim off any combination of carriage returns and newlines from the end of s:

s = s.TrimEnd(new char[] { '\r', '\n' });

编辑:或者,JP指出,您可以更简洁地将其拼写为:

Edit: Or as JP kindly points out, you can spell that more succinctly as:

s = s.TrimEnd('\r', '\n');