I want to split my string just by empty entries. I know you can remove these with the string options but in my situation I need them to split the string. Thank you!
string[] text = content.Split(' ');
For example you have this string:
Hi my Name is Max.
I'm 24 years old.
I like programming.
Split the string between old and I.
My Code:
WebClient client = new WebClient();
Stream stream = client.OpenRead("https://gist.githubusercontent.com/Quackmatic/f8deb2b64dd07ea0985d/raw/macbeth.txt");
StreamReader reader = new StreamReader(stream);
string[] text = reader.ReadToEnd().Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < 3; i++)
{
Console.WriteLine(text[i]);
}
Console.ReadLine();
The string is splitted by every new line. The problem is I want to have full paragraphs of my text.
My Output:
string[0] = ACT I.
string[1] = SCENE I. An open place.
string[2] =[An open place. Thunder and lightning. Enter three Witches.]
What I want.
string[0] = ACT I.
string[1] = SCENE I. An open place.
[An open place. Thunder and lightning. Enter three Witches.]
string[2] = FIRST WITCH.
When shall we three meet again
In thunder, lightning, or in rain?
or...
Doubtful it stood;
As two spent swimmers that do cling together
And choke their art. The merciless Macdonwald,
Worthy to be a rebel, for to that
The multiplying villainies of nature
Do swarm upon him, from the Western isles
Of kerns and gallowglasses is supplied;
And fortune, on his damned quarrel smiling,
Show'd like a rebel's whore. But all's too weak;
For brave Macbeth, well he deserves that name,
Disdaining fortune, with his brandish'd steel,
Which smok'd with bloody execution,
Like valour's minion,
Carv'd out his passage, till he fac'd the slave;
And ne'er shook hands, nor bade farewell to him,
Till he unseam'd him from the nave to the chaps,
And fix'd his head upon our battlements
I thought I could get the result by splitting the text by empty lines. .