拆分逗号分隔值 [英] Split comma-separated values
本文介绍了拆分逗号分隔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Visual Studio 2005和C#2.0中,我试图使用 string.Split
功能和Lambda表达式如下拆分逗号分隔字符串:
I am using Visual Studio 2005 and C# 2.0, and I am trying to split a comma-separated string using the string.Split
function and a lambda expression as follows:
string s = "a,b, b, c";
string[] values = s.Split(',').Select(sValue => sValue.Trim()).ToArray();
我得到一个错误说,表达不承认? - 我怎么能解决这个
I get an error saying that the expression is not recognized -- how can I resolve this?
推荐答案
.NET 2.0不支持LINQ - 的 SO线程;结果
但是你可以创建一个VS2005项目3.5 - 的 MSDN线程
.NET 2.0 does not support LINQ - SO thread;
But you can create a 3.5 project in VS2005 - MSDN thread
没有拉姆达的支持,你需要做这样的事情:
Without lambda support, you'll need to do something like this:
string s = "a,b, b, c";
string[] values = s.Split(',');
for(int i = 0; i < values.Length; i++)
{
values[i] = values[i].Trim();
}
这篇关于拆分逗号分隔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文