我有一个包含48行整数的CSV文件。我使用visual c#的openfiledialog功能来允许用户选择这个文件。然后我想让程序将该文件截断为24行。是否有一个截断函数可以用来轻松地完成这项工作?如果不是,我该怎么做呢?下面是我迄今为止...C#截断CSV文件#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace sts_converter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void select_Click(object sender, EventArgs e)
{
int size = -1;
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
}
catch (IOException)
{
}
}
Console.WriteLine(size); // <-- Shows file size in debugging mode.
Console.WriteLine(result); // <-- For debugging use only.
}
}
}
+1好问题,因为我发现/获悉,为Linq的`Take`方法的使用。 – 2010-12-02 18:27:06