I have the following expression:
"<p>What ?</p>\n<pre>Starting Mini</pre>"
When I perform a split as follows:
var split = content
.Split(new[] { "<pre>", "</pre>" }, StringSplitOptions.None);
Then it gives me three entries:
"<p>What ?</p>\n"
"Starting Mini"
""
Why does it give an empty line as the third entry and how can I avoid this?
The “why” is simply: the input (if you don’t remove empty entries) will always “split” at any occurrence of the separator(s), so if the separator(s) appear
ntimes in the string, then the array will ben+1long. In particular, this essentially lets you know where they occurred in the original string (although when using multiple separators, it doesn’t let you know which appeared where).For example, with a simple example (csv without any escaping etc):
The fix is, as already mentioned, to use
RemoveEmptyEntries.