【发布时间】:2012-08-02 13:20:55
【问题描述】:
我的字符串有问题。 字符串是这样的:
string something = " whatever and something else ";
现在我正在尝试像这样摆脱开头和结尾的空格:
something = something.Trim();
但这没有用,我也试过这个:
something = something.TrimStart();
something = something.TrimEnd();
还有这个:
something = something.TrimStart(' ');
something = something.TrimEnd(' ');
还有这个:
int lineLength = line.Length;
string LastCharacter = line.Remove(lineLength - 1);
while (LastCharacter == " ")
{
line = line.Remove(lineLength - 1);
lineLength = line.Length;
LastCharacter = line.Remove(lineLength - 1);
}
字符串超出 RichTextBox。
现在我认为这可能是文本格式或其他问题(我在德国)。
提前谢谢你, tietze111
【问题讨论】:
-
您使用什么语言?
The string is like this: ...“喜欢”是什么意思?那是您拥有的 exact 字符串吗?如果不是,你从哪里得到字符串,当转换为 int 时每个字符的值是多少? -
.Trim() 应该按您的预期工作,您使用它是正确的。问题在于您的字符串中包含的文本。
-
感谢您的回答,文本来自richTextBox,对不起,我忘记了语言,它是C#
标签: c# string space trim spaces