안녕하세요,
아래 c# 코드를 이용해 CSV파일을 읽어오고 있습니다.
public class CSVReader
{
private static readonly string SPLIT_RE = @",(?=(?:[^""]*""[^""]*"")*(?![^""]*""))";
private static readonly string LINE_SPLIT_RE = @"\r\n|\n\r|\n|\r";
private static readonly char[] TRIM_CHARS = { '\"' };
public static List<Dictionary<string, object>> Read(string path)
{
var list = new List<Dictionary<string, object>>();
TextAsset data = Resources.Load(path) as TextAsset;
var lines = Regex.Split(data.text, LINE_SPLIT_RE);
if (lines.Length <= 1) return list;
var header = Regex.Split(lines[0], SPLIT_RE);
for (var i = 1; i < lines.Length; i++)
{
var values = Regex.Split(lines[i], SPLIT_RE);
if (values.Length == 0 || values[0] == "") continue;
var entry = new Dictionary<string, object>();
for (var j = 0; j < header.Length && j < values.Length; j++)
{
string value = values[j];
value = value.TrimStart(TRIM_CHARS).TrimEnd(TRIM_CHARS).Replace("\\", "");
object finalvalue = value;
int n;
float f;
if (int.TryParse(value, out n))
{
finalvalue = n;
}
else if (float.TryParse(value, out f))
{
finalvalue = f;
}
entry[header[j]] = finalvalue;
}
list.Add(entry);
}
return list;
}
}
엑셀 파일을 CSV로 변환해 다른 파일들은 잘 굴리고 있었는데요,
셀 안에 쉼표가 포함된 문장이 들어있어
CSV로 변환 후 읽어오려고하면 에러가 발생합니다.
아래는 예시입니다.
어떤식으로 해결해야할까요?? 조언 부탁드립니다.
csv파일로 분리하는 키워드?(기본 ,)를 |나 *같은 다른걸로 바꾼 뒤 읽어와야할까요?