/// <summary> /// 自台鐵票價資訊之CSV列轉換為票價資訊 /// </summary> /// <param name="csvString">CSV列</param> /// <returns>票價資訊</returns> internal static Fare[] Parse(string csvString) { var splited = csvString.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); var baseInfo = splited.Take(4).Select(x => double.Parse(x)).ToArray(); List<string[]> fareInfo = new List<string[]>(); for (int i = 4; i < splited.Length - 2; i += 5) { fareInfo.Add(splited.Skip(i).Take(3).ToArray()); } List<Fare> result = new List<Fare>(); ; for (int i = 0; i < fareInfo.Count; i++) { for (int j = 0; j < 3; j++) { var item = new Fare(); item._Starting = (int)baseInfo[0]; item._Arrival = (int)baseInfo[1]; item.Direction = (TrainDirection)(int)baseInfo[2]-1; item.Mileage = baseInfo[3]; item.TrainType = (TrainLevels)(i * 10); item.FareType = (FareTypes)j; item.Price = int.Parse(fareInfo[i][j]); result.Add(item); } } return result.ToArray(); }