분할 문자열에 대한 질문이 있고 DataTable에 넣습니다. 두 번째 배열이 문자열인지 숫자인지 어떻게 알 수 있습니까?분할 문자열 및 DataTable 넣어 두 번째 인덱스 번호를 찾으십시오
text : ...
abc 123 def 1 \"ok lo\" ;
abc def 1 \"ok lo\" ;
...
배열 2 :
tmpList[0] = abc
tmpList[1] = 123
tmpList[2] = def
tmpList[3] = 1 \"ok lo\"
배열 1 : 내가 한
tmpList[0] = abc
tmpList[1] = def
tmpList[2] = 1 \"ok lo\
모든 문자열을 찾으려면 startwith ABC :
나는이 같은 많은 캐릭터와 텍스트가
StreamReader fin = new StreamReader(userSelectedFilePath1);
string tmp = "";
while ((tmp = fin.ReadLine()) != null)
{
if (tmp.StartsWith("abc "))
{
var tmpList1 = tmp.Split(new[] { '"' }).SelectMany((s, i) =>
{
if (i % 2 == 1) return new[] { s };
return s.Split(new[] { ' ', ';', ',' }, StringSplitOptions.RemoveEmptyEntries);
}).ToList();
table.Rows.Add(new object[] { tmpList1[0], tmpList1[1], tmpList1[2], tmpList1[3]});
}
}
이 코드를 사용하면 String startswith abc, split을 찾고 DataTable에 넣을 수 있습니다. 두 번째 인덱스가 문자열인지 int인지 어떻게 알 수 있습니까? 내가 무엇을했는지와 함께 나는 두 번째 색인에 오류가 있었으며 그것은 correcly가 아니었다. 나는뿐만 아니라에 대한 if(tmp.StartsWith(abc NUMBER?))
else
당신 사항 String.split()를 수행 할 때
귀하의 질문이 "달성하려는 대상"인 경우 누구나 쉽게 대답 할 수 있습니다. 테이블 스키마가 무엇입니까? 왜 두 번째 배열이 int 여야합니까? –