Html:
<body>
<textarea readonly id="txtImagename1" name="txtImagename1" rows="1000" cols="200">
testing
second line
</textarea>
</body>
</html>
How can I get the text in the textarea by c# code?
(testing\nsecond line)
Html:
<body>
<textarea readonly id="txtImagename1" name="txtImagename1" rows="1000" cols="200">
testing
second line
</textarea>
</body>
</html>
How can I get the text in the textarea by c# code?
(testing\nsecond line)
You should use a dedicated HTML parser.
However, if this is a quick-and-dirty requirement, you could use a regex with a capturing group, something like this:
var html = <your HTML for parsing>;
var pattern = @"<textarea.*>([.\s\S]*)</textarea>";
var matches = Regex.Matches(html, pattern);
if (matches.Count > 0 && matches[0].Groups.Count > 1)
...
You can then extract the captured group (the part in round brackets in the regex) using something like:
var text = match.Groups[1].Captures[1];
See this answer for more details.
This is brittle and I do not recommend this for re-use or production code.