Further to solutions 1 and 2 but in light of the sample data you subsequently posted, the following function will handle a continuous stream of text which is to be separated into clauses based on "a)", "b)", "c)" etc up to "z)"
private string NewLinesBetweenClauses(string inputString, string nl)
{
var separators = Enumerable.Range(0, 26).Select(x => ((char)(x + 'a')).ToString() + ') ').ToArray();
var tempString = inputString.Replace("(s)", "%s%");
var clauses = tempString.Split(separators, StringSplitOptions.RemoveEmptyEntries);
var newString = new StringBuilder("");
for (var i = 0; i < clauses.Length; i++)
{
newString.Append(separators[i]);
newString.Append(clauses[i].Replace("%s%", "(s)"));
newString.Append(nl);
}
return newString.ToString();
}
Key points are handling any "(s)" in the text that shouldn't be split with a new-line the way that "s) " should.
Note that any phrases in brackets (for example) will cause issues
If you don't want to use Linq to generate the separators then the following will also do it
string[] separators = new string[26];
for (int i = 0; i < 26; i++)
separators[i] = ((char)(i + 'a')).ToString() + ') ';
The parameter
nl
is passed in so that it can be used with HTML newline or winforms style newlines. e.g.
var inputString = "a) In the name(s)……………………….and ………………………. b) In the case of minor, his date of birth……………………encashable by the minor’s parent/guardian Shri/Smt ………. c) Agent’s name …………………………….. d) Certificate of Authority No……………………..";
Console.WriteLine(NewLinesBetweenClauses2(inputString, "<br/>"));
Console.WriteLine(NewLinesBetweenClauses2(inputString, Environment.NewLine));