lol*_*ola 1 c# string return-value immutability
我的变量看起来像:
name = "Lola "; // notice the whitespace
Run Code Online (Sandbox Code Playgroud)
我怎样才能删除最后的空白,只留下"萝拉"?
谢谢大家,但.Trim()对我不起作用.
我从文件中读取文本,如果有任何帮助的话.
Jan*_*oom 17
用Trim().
string name = "Lola "
Console.WriteLine(name.Trim()); // puts out 'Lola'
Run Code Online (Sandbox Code Playgroud)
如果空格始终位于字符串的末尾,请使用:
name = name.TrimEnd();
Run Code Online (Sandbox Code Playgroud)
如果空间也可能在开头,那么使用:
name = name.Trim();
Run Code Online (Sandbox Code Playgroud)