[英]Parsing string and making list of required data
我正在使用以下代碼中的**<style>..{data inside}..</style>**
。我已將所有樣式標簽之間的數據收集在一個字符串中,例如, 字符串tempStyle和所有操作都是僅在該字符串上完成。
我正在尋找功能,將使所有“樣式”數據的列表。 即僅將style1,style2,style15,style20放入列表<>中。
我不想在List <>中使用正確的td,table標簽,我只想將list中的樣式數據與另一個List進行比較。 我只是在尋找使樣式數據的List <>出現在樣式標簽之間的函數。
請參考以下代碼以了解問題。
提前。
<html>
<head>
<style>
.right {
}
td{
}
table{
}
.style1{
}
.style2{
}
.style15{
}
.style20{
}
</style>
</head>
</html>
正則表達式可以很好地做到這一點:
class Program
{
private const string PATTERN = @".style[\d]+{[^}]*}";
private const string STYLE_STRING = @" .right { } td{ } table{ } .style1{ } .style2{ } .style15{ } .style20{ }";
static void Main(string[] args)
{
var matches = Regex.Matches(STYLE_STRING, PATTERN);
var styleList = new List<string>();
for (int i = 0; i < matches.Count; i++)
{
styleList.Add(matches[i].ToString());
}
styleList.ForEach(Console.WriteLine);
Console.ReadLine();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.