private async Task AddItemToFileAsync(StorageFolder folder, string fileName, ICsvItem item) { var lines = await FileIOEx.ReadFileAsync(folder, fileName, "Shift-JIS"); var isExist = false; for (int i = 0; i < lines.Count; i++) { string[] cols = lines[i].Split(','); if (cols[0] == item.CsvRawName) { lines[i] = item.GetCsvRaw(); isExist = true; } } if (!isExist) { lines.Add(item.GetCsvRaw()); } await FileIOEx.SaveFileAsync(folder, fileName, lines, "Shift-JIS"); }
private async Task RemoveItemToFileAsync(StorageFolder folder, string fileName, ICsvItem item) { var lines = await FileIOEx.ReadFileAsync(folder, fileName, "Shift-JIS"); var existIndex = -1; for (int i = 0; i < lines.Count; i++) { string[] cols = lines[i].Split(','); if (cols[0] == item.CsvRawName) { existIndex = i; break; } } if (existIndex != -1) { lines.RemoveAt(existIndex); } await FileIOEx.SaveFileAsync(folder, fileName, lines, "Shift-JIS"); }