I can not understand the essence of what is simple 2 lines of code but the compiler is wise:

string text = " TITLE OF THE DOCUMEN </ title ></ head >< body >< h1 > hello </ h1 >"; text = text.Substring(22, 31); 

After compilation produces " </ title ></ head >< body >< h1 ". What is the problem?

2 answers 2

We climb into msdn, see what the substring method does .
We see that the second parameter is the length of the substring, and not the end position.

    There is no problem, what you wrote is what you get. The string "</ title ></ head >< body >< h1" exactly 31 characters, and this substring starts at just 22 characters.