public string TrimEnd ();
member this.TrimEnd : unit -> string
Public Function TrimEnd () As String
方法
TrimEnd
从当前字符串中删除所有尾随空格字符。 在字符串末尾遇到第一个非空格字符时,剪裁操作将停止。 例如,如果当前字符串为“abc xyz”,则
TrimEnd
该方法返回“abc xyz”。
TrimEnd
如果方法从当前实例中删除任何字符,则此方法不会修改当前实例的值。 而是返回一个新字符串,其中所有尾随空格字符都将从当前字符串中删除。
System::String ^ TrimEnd(char trimChar);
public string TrimEnd (char trimChar);
member this.TrimEnd : char -> string
Public Function TrimEnd (trimChar As Char) As String
方法
TrimEnd(System.Char)
从当前字符串中删除所有尾随
trimChar
字符。 当字符串末尾遇到第一个字符时
trimChar
,剪裁操作将停止。 例如,如果
trimChar
为
-
且当前字符串为“---abc---xyz----”,则
TrimEnd(System.Char)
该方法返回“---abc---xyz”。
TrimEnd(System.Char)
如果方法从当前实例中删除任何字符,则此方法不会修改当前实例的值。 相反,它返回一个新字符串,其中所有尾随
trimChar
字符都将从当前字符串中删除。
public:
System::String ^ TrimEnd(... cli::array <char> ^ trimChars);
public string TrimEnd (params char[] trimChars);
public string TrimEnd (params char[]? trimChars);
member this.TrimEnd : char[] -> string
Public Function TrimEnd (ParamArray trimChars As Char()) As String
以下示例演示如何使用
TrimEnd(System.Char[])
方法从字符串末尾剪裁空格或标点符号。
string sentence = "The dog had a bone, a ball, and other toys.";
char[] charsToTrim = {',', '.', ' '};
string[] words = sentence.Split();
foreach (string word in words)
Console.WriteLine(word.TrimEnd(charsToTrim));
// The example displays the following output:
// The
// dog
// had
// a
// bone
// a
// ball
// and
// other
// toys
let sentence = "The dog had a bone, a ball, and other toys."
let charsToTrim = [| ','; '.'; ' ' |]
let words = sentence.Split()
for word in words do
printfn $"{word.TrimEnd charsToTrim}"
// The example displays the following output:
// The
// dog
// had
// a
// bone
// a
// ball
// and
// other
// toys
Module TrimEnd
Public Sub Main()
Dim sentence As String = "The dog had a bone, a ball, and other toys."
Dim charsToTrim() As Char = {","c, "."c, " "c}
Dim words() As String = sentence.Split()
For Each word As String In words
Console.WriteLine(word.TrimEnd(charsToTrim))
End Sub
End Module
' The example displays the following output:
' The
' dog
' had
' a
' bone
' a
' ball
' and
' other
' toys
方法
TrimEnd(System.Char[])
从当前字符串中删除 参数中的所有
trimChars
尾随字符。 当字符串末尾遇到不在 中的
trimChars
第一个字符时,剪裁操作将停止。 例如,如果当前字符串为“123abc456xyz789”,并且
trimChars
包含“1”到“9”的数字,则
TrimEnd(System.Char[])
该方法返回“123abc456xyz”。
TrimEnd(System.Char[])
如果方法从当前实例中删除任何字符,则此方法不会修改当前实例的值。 相反,它将返回一个新字符串,其中找到
trimChars
的所有尾随字符将从当前字符串中删除。
调用方说明
.NET Framework 3.5 SP1 及更早版本维护此方法在 为
null
时
trimChars
剪裁的内部空白字符列表或空数组。 从 .NET Framework 4 开始,如果
trimChars
为
null
或为空数组,该方法将剪裁所有 Unicode 空白字符, (即在传递给
IsWhiteSpace(Char)
方法) 时生成
true
返回值的字符。 由于此更改,
Trim()
.NET Framework 3.5 SP1 及更早版本中的 方法删除了两个字符:零宽度空格 (U+200B) 和零宽度 NO-BREAK 空格 (U+FEFF) ,.NET Framework
Trim()
4 及更高版本中的方法不会删除。 此外,
Trim()
.NET Framework 3.5 SP1 及更早版本中的 方法不会剪裁三个 Unicode 空白字符:MONGOLIAN 元音分隔符 (U+180E) 、NARROW NO-BREAK SPACE (U+202F) 和 MEDIUM MATHEMATICAL SPACE (U+205F) 。