C# Trim() 方法用于从当前 String 对象中删除所有前导和尾随空白字符。
public string Trim() public string Trim(params Char[])
第一种方法不带任何参数。第二种方法将 char 数组作为参数。
它返回一个字符串。
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";
string s2 = s1.Trim();
Console.WriteLine(s2);
}
}
输出:
Hello C#
