WP7 - 从CSV文件读取?或者如何处理数据?如何处理、文件、数据、CSV

2023-09-06 07:23:47 作者:退回无路

我有数据的CSV文件,该文件我试图在我的Windows Phone 7的应用程序中使用。 我试图找出如何打开和使用数据在我的应用程序。我见过一些例子各地有关使用LINQ要做到这一点,但他们使用OLEDB来打开CSV文件。

I have a CSV file of data which I'm attempting to use in my Windows Phone 7 application. I'm trying to figure out how to open and consume the data in my app. I've seen some examples around about using Linq to do this, but they use OleDB to open the CSV file.

注:我想将数据与我的应用程序部署,而不是使用Web服务,因为它是清洁,没有那么多的数据。如果没有编码的方式来做到这一点,也许是一种方式来转换为XML?

Note: I want to deploy the data with my app, instead of using a Web Service, because it is cleaner and not that much data. If there is no coding way to do it, perhaps a way to convert to XML?

推荐答案

没有错,使用重量轻CSV输入文件。

Nothing wrong with using light weight CSV input files.

您可以使用StreamReader.Readline在一个行上,一次拉。

You can use StreamReader.Readline to pull in a line at a time.

和String.Split来分析逗号分隔值转化为可用的元素。例如:

And String.Split to parse the comma seperated values into usable elements. For example:

string csv = "abc,123,def,456";
string[] elements = csv.Split(',');
foreach (string s in elements)
    System.Diagnostics.Debug.WriteLine(s);
 
精彩推荐
图片推荐