나는이 코드를 C#에서 EF Core 1.2를 사용하여 어디에서 텍스트 영역의 입력을 읽고 어떤 패턴이 내 패턴과 일치하는지 확인합니다. 한 줄을 확인한 후 한 패턴과 일치하는지 알려주는 상태를 설정하려고합니다.문자열과 해당 상태를 List에 저장하는 방법은 무엇입니까?
이제 각 행에 테이블의 각 상태를 표시하려는 내 뷰에이 목록을 전달할 수 있도록 임시로 각 상태를 목록에 저장하는 것이 좋습니다.
제 문제는 각 행과 상태를 어떻게 저장합니까? 나는 사전을 사용하는 것에 대해 생각했지만 이것이 내 문제에 대한 최선의 해결책인지 확신 할 수 없다. Dictionary
를 사용
using (StringReader reader = new StringReader(Request.Form["ExpressionTextarea"].ToString()))
{
string line = string.Empty;
do
{
line = reader.ReadLine();
if (line != null)
{
string state = CheckStringLine(line);
/**** HOW TO SAVE EACH LINE PLUS ITS STATE TEMPORARILY?
//IDictionary<string, string> dictionary = new Dictionary<string, string>();
//dictionary.Add(line, status);
****/
}
} while (line != null);
//***PASSING MY LIST TO MY VIEW
return View(MYLIST);
}
//Checks if line matches a pattern
public string CheckStringLine(string Line)
{
string state = "";
//Pattern1: (Ein | Eine) A ist (ein | eine) B.
string pattern1 = @"^(?<Artikel1>(Ein|Eine){1})\s{1}(?<Second>[A-Z]{1}[a-zäöüß]{1,})\s{1}ist\s{1}(?<Artikel2>(eine|ein){1})\s(?<Fourth>[A-Z]{1}[a-zäöüß]{1,})\.$";
//Pattern2: (Ein | Eine) A (oder (ein | eine) B)+ ist (ein | eine) C.
string pattern2 = @"^(?<First>(Ein|Eine){1})\s{1}(?<Second>[A-Z]{1}[a-zäöüß]{1,})(\s{1}oder\s{1}(?<OptionalArtikel>(ein|eine){1})\s{1}(?<OptionalBegriff>[A-Z]{1}[a-zäöüß]{1,}))+(\s{1})ist\s{1}(?<Third>(eine|ein){1})\s(?<Fourth>[A-Z]{1}[a-zäöüß]{1,})\.$";
var match1 = Regex.Match(Line, pattern1);
var match2 = Regex.Match(Line, pattern2);
if (match1.Success)
{
state = "This Line is using pattern1";
return state;
}
if (match2.Success)
{
state = "This Line is using pattern2";
return state;
}
state = "No matches";
return state;
}
사전은 모든 키가 고유 한 한 좋은 소리입니다. 그렇지 않으면 C# 7의 튜플 데이터 유형 –