Count the number of characters between opening and closing "<" and ">" for the whole file
You can do it with regex as follows:
var brackets = new char[] {'<', '>'};
int counter = 0;
foreach (var match in System.Text.RegularExpressions.Regex.Matches(data, @"</?[^<>]+>"))
counter += match.ToString().Trim(brackets).TrimStart('/').Length;
This also correctly considers end tags if you have tags too.
, , , , :
string s = System.IO.File.ReadAllText("myfile.txt");
bool inbrackets = false;
int count = 0;
foreach (char ch in s)
{
if (ch == '<')
inbrackets = true;
else if (ch == '>')
inbrackets = false;
else if (inbrackets)
++count;
}
System.Console.WriteLine("count = " + count);
. , int bool. , , .
Assuming there are no nesting shortcuts and you have well-formed input
var charcount = File.ReadAllText("C:\foo.txt").Split('<')
.Select(x => x.IndexOf('>')).Where(x => x > 0).Sum();
If you have nesting or require error checking, obviously, you will need to write something more thorough.