0

这些是 CSV 文件的内容 -

heightAscent,altitudeDescent,altitudeavg,altitudecurrent,altitudeend,altitudemax,altitudemin,altitudestart,calories,className,createAppVersion,createDevice,createIOSVersion,distance,eaType,ecomodule,elapsedSeconds,fatCalories,footpodElapsedSecondsInterval,gpsSensor,gps_distance,gps_maxspeed,heartSensor,isCompletedAssessment,isLocationIndoors, isgpsonly,maxBPM,maxspeed,minBPM,otherWorkoutTypeName,otherzonetimes,primarySourceSpeedDistance,readCountBPM,routineds,routineid,startLat,startLon,startTime,totalBeats,totalDurationSeconds,totalPausedSeconds 0,2.37,-999999,33.66,33.66,42.76,20.21,36.47,48, ActiveWorkout, 7.00 ,iPhone5,1,7.0,0.27,0,1024,2657,207.77,2655,ios,0.27,3.69,ble,NO,NO,YES,186,3.69,87,举重,85,gps,884 ,4.000000,TEMP-1663889272,37.10730362,-76.50557709,2013-08-26T18:48:21,110056,0,0

我需要从 CSV 文件中删除“7.00”值。我如何在 VB 或 C# 中做到这一点?

4

3 回答 3

3
string names;
List<string> values;
using (var stream = new StreamReader("path/to/file.csv"))
{
    names = stream.ReadLine();
    values = stream.ReadLine().Split(',').ToList();
}
values.RemoveAt(9);
names; // first part of file
string secondPartOfFile = string.Join(",", values);
于 2013-10-13T23:05:13.233 回答
1
  1. 我将使用此处找到的连接字符串或此处的示例连接到文件,将其加载到 DataTable 对象中,然后执行此操作(假设您将变量称为“dt”):

    dt["columnName"][rowNumber] = string.Empty;

  2. 如果你总是让它等于 7.00,那么你可以使用 TextReader 读取文件,然后执行类似的操作yourFile = yourFile.Replace(",7.00,", ",,");

这取决于您的场景,也许您甚至可以以更适合工作的格式获取数据,例如 JSON 对象或其他东西。

于 2013-10-13T23:05:01.060 回答
1

这对我有用

 var sr = new StreamReader("file.csv");
            var writeToFile = new StreamWriter("out.csv");
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                writeToFile.WriteLine(sr.ReadLine().ToString().Replace(",7.00", ""));
            }
            writeToFile.Close();
            sr.Close();
于 2013-10-13T23:46:35.850 回答