나는 매트릭스 객체에 익숙하지 해요,하지만 이것은 당신이 2 차원 문자열 배열로 해당 문자열을 구문 분석하는 방법이다. 그것이 당신을 올바른 길로 인도 할 수 있기를 바랍니다.
string people = "Prof. Dr. Bill Gates;[email protected];Microsoft Corporation!Dr.Elon Musk; elon @tesla.com; Tesle Inc.!Dr.Mehdi Karakoç; mehdi @tetra.com.tr; Tetra Yazılım!";
string[] tmp;
int maxWidth = 0;
int row;
List<string[]> everybody = new List<string[]>();
string[] folks = people.Split('!');
string[,] matrix;
foreach (string person in folks)
{
tmp = person.Split(';');
maxWidth = Math.Max(maxWidth, tmp.Length);
everybody.Add(tmp);
}
matrix = new string[everybody.Count, maxWidth];
row = 0;
foreach (string[] body in everybody)
{
for (int i = 0; i < maxWidth; i++)
{
if (i < body.Length)
{
matrix[row, i] = body[i];
}//if this person has enough entries
}//for each value in person
row++;
}//for each person
//Result is now a 2 dimensional string array, parsed per value per person.
그래서? 아직 아무 것도 시도하지 않았습니까? 무엇을 시도했는지 작동하지 않는 것은 무엇입니까? (SO는 코드 서비스 사이트가 아닙니다 ..) –
'string.Split (';')' –
var simple = people.Split ('!'). 여기서 (p =>! string.IsNullOrWhiteSpace (p)). (p => p.Split (';')) .ToArray(); – Rob