我需要检查c#中的复杂属性。我得到的复杂属性List of string是:
EmployeeID
contactNo
Employee.FirstName // these is complex property
Employee.LastName // these is complex property
我知道regex.match()但是我怀疑如何在放入点值之后检查字符串,这意味着我想要检查Employee和放置点值之后。你能帮忙解决一下吗?
答案 0 :(得分:1)
使用正则表达式,您可以匹配如下的复杂属性:
List<string> properties = new List<string>()
{
"EmployeeID",
"contactNo",
"Employee.FirstName", // these is complex property
"Employee.LastName", // these is complex property
};
Regex rgx = new Regex(@"Employee\.(.*)");
var results = new List<string>();
foreach(var prop in properties)
{
foreach (var match in rgx.Matches(prop))
{
results.Add(match.ToString());
}
}
如果你只想要.
(FirstName
和LastName
)之后的内容,请替换这样的模式:
Regex rgx = new Regex(@"(?<=Employee\.)\w*");
答案 1 :(得分:0)
没有正则表达式:
login api
如果您只需要匹配List<string> listofstring = { .... };
List<string> results = new List<string>();
const string toMatch = "Employee.";
foreach (string str in listofstring)
{
if (str.StartsWith(toMatch))
{
results.Add(str.Substring(toMatch.Length));
}
}
.