That's because you only count and process lines containing "<L1" - The other elements in your sample start with "<H" or <"P" so they are ignored.
Quote:
Really, it's mean you tried it before. But the results like that or not?
No, but I just tried it: it's not a complex task.
Create a class to hold tag info:
protected sealed class TagItem
{
public int StartIndex { get; set; }
public int EndIndex { get; set; }
public int TagsCount { get; set; }
public TagItem Parent { get; set; }
public override string ToString()
{
return $"Start : {StartIndex}\nEnd : {EndIndex}\nContains: {TagsCount}";
}
}
Then create a List to hold them as you find them and a "current tag" variable so you know what a new tag belongs to:
List<TagItem> tags = new List<TagItem>();
TagItem currentTag = null;
Then look at each character in the input string (no need to Split it!) looking for start and end tags.
For a start, count it on the current tag (if there is one), create a new TagItem with the character index and current tag as its parent, then add that to the List and set the new current tag.
For an end, set the end index on the current tag, and set it back to it's parent.
After the loop, print counts for all the non-zero tags:
Console.WriteLine(string.Join(",", tags.Where(t => t.TagsCount > 0).Select(t => t.TagsCount)));
5 minutes of typing, or so?
Result: "2,1,3,1"