我需要從列表中獲取沒有前導空格或尾隨空格的項目。我嘗試使用以下代碼,但仍然使用Trim()函數刪除字符串的尾部空格。爲什麼會發生?使用TRIM去除尾隨空白()
string ab = string.Empty;
ab += "first" + ", ";//adding a white space to the string
ab += "second" + ", ";
ab += "third" + ", ";
List<string> ls = ab.ToString().Split(',').ToList();//first, second, third,
foreach (string item in ls)
{
item.Trim();//need to remove the space
string a = item;//here still got the white space
}