[英]Is it possible to prevent Trim() from removing a space?
This might seem like an odd question, but is there any way of putting space in a string in such a way that Trim()
will not remove it?这似乎是一个奇怪的问题,但是有没有办法以
Trim()
不会删除它的方式在字符串中放置空格?
eg I want the output to be, for example, "Hello, World "
(this is how I want it to be displayed).例如,我希望输出是,例如,
"Hello, World "
(这是我希望它的显示方式)。
The obvious answer is, don't call Trim()
, unfortunately in this case I am passing the string into a library (to which I don't have the source code) and that library is doing the trimming.显而易见的答案是,不要调用
Trim()
,不幸的是,在这种情况下,我将字符串传递到一个库中(我没有源代码)并且该库正在进行修剪。
Maybe there's a character that looks like a space but isn't really and so won't be trimmed?也许有一个角色看起来像一个空格,但实际上不是,所以不会被修剪? Or some invisible character to put at the end of the string?
或者一些不可见的字符放在字符串的末尾?
Use a different write space, it may or may not work for you使用不同的写入空间,它可能适合您,也可能不适合您
var str = "test ";
var str2 = str.Replace(" ", "\u00A0");
Any of these really任何这些真的
U+00A0 NO-BREAK SPACE
U+1680 OGHAM SPACE MARK
U+180E MONGOLIAN VOWEL SEPARATOR
U+2000 EN QUAD
U+2001 EM QUAD
U+2002 EN SPACE (nut)
U+2003 EM SPACE (mutton)
U+2004 THREE-PER-EM SPACE (thick space)
U+2005 FOUR-PER-EM SPACE (mid space)
U+2006 SIX-PER-EM SPACE
U+2007 FIGURE SPACE
U+2008 PUNCTUATION SPACE
U+2009 THIN SPACE
U+200A HAIR SPACE
U+200B ZERO WIDTH SPACE
U+202F NARROW NO-BREAK SPACE
U+205F MEDIUM MATHEMATICAL SPACE
U+3000 IDEOGRAPHIC SPACE
U+FEFF ZERO WIDTH NO-BREAK SPACE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.