这是我的源字符串:
<box><3>
<table><1>
<chair><8>这是我的Regex Patern:
<(?<item>\w+?)><(?<count>\d+?)>这是我的Item类
class Item
{
string Name;
int count;
//(...)
}这是我的项目集合;
List<Item> OrderList = new List(Item);我想用基于源字符串的项填充该列表。这是我的功能。这不管用。
Regex ItemRegex = new Regex(@"<(?<item>\w+?)><(?<count>\d+?)>", RegexOptions.Compiled);
foreach (Match ItemMatch in ItemRegex.Matches(sourceString))
{
Item temp = new Item(ItemMatch.Groups["item"].ToString(), int.Parse(ItemMatch.Groups["count"].ToString()));
OrderList.Add(temp);
}这里可能有一些小错误,比如在这个例子中遗漏了字母it,因为这是我的应用程序中更简单的版本。
问题是,最终我在OrderList中只有一项。
更新
我把它修好了。他们需要帮助。
https://stackoverflow.com/questions/5767605
复制相似问题