You were pretty much there. The following code takes this input
1. The <title> element 50m 45s
defines a title in the browser toolbar 15m 20s
provides a title for the page when it is added to favorites 15m 10s
displays a title for the page in search-engine results 20m 15s
2. CSS can be added to HTML in the following ways 21m 40s
Inline - using the style attribute in HTML elements 5m 10s
Internal - using the <style> element in the <head> section 10m 3s
External - using an external CSS file 6m 27s
and provides this output which from what i gather is your desired output.
<ul>
<li>1. The <title> element 50m 45s</li>
<li>defines a title in the browser toolbar 15m 20s</li>
<li>provides a title for the page when it is added to favorites 15m 10s</li>
<li>displays a title for the page in search-engine results 20m 15s</li>
<li>2. CSS can be added to HTML in the following ways 21m 40s</li>
<li>Inline - using the style attribute in HTML elements 5m 10s</li>
<li>Internal - using the <style> element in the <head> section 10m 3s</li>
<li>External - using an external CSS file 6m 27s</li>
</ul>
I am pretty much using what you had in your comment above.
var inputValue =
@"1. The <title> element 50m 45s
defines a title in the browser toolbar 15m 20s
provides a title for the page when it is added to favorites 15m 10s
displays a title for the page in search-engine results 20m 15s
2. CSS can be added to HTML in the following ways 21m 40s
Inline - using the style attribute in HTML elements 5m 10s
Internal - using the <style> element in the <head> section 10m 3s
External - using an external CSS file 6m 27s";
var lines = inputValue.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
var buildstr = new StringBuilder();
buildstr.Append("<ul>" + Environment.NewLine);
foreach (var line in lines)
{
buildstr.AppendFormat("<li>{0}{1}</li>", line.Trim(), Environment.NewLine);
}
buildstr.Append("</ul>" + Environment.NewLine);
Console.WriteLine(buildstr.ToString());
If you desire to remove the times this method using Linq and Regex to remove the times.
var inputValue =
@"1. The <title> element 50m 45s
defines a title in the browser toolbar 15m 20s
provides a title for the page when it is added to favorites 15m 10s
displays a title for the page in search-engine results 20m 15s
2. CSS can be added to HTML in the following ways 21m 40s
Inline - using the style attribute in HTML elements 5m 10s
Internal - using the <style> element in the <head> section 10m 3s
External - using an external CSS file 6m 27s";
var lines = inputValue.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
var buildstr = new StringBuilder();
buildstr.Append("<ul>" + Environment.NewLine);
foreach (string newline in lines.Select(line => Regex.Replace(line, "[0-9]+s", "")).Select(newline => Regex.Replace(newline, "[0-9]+m", "")))
{
buildstr.AppendFormat("<li>{0}</li>{1}", newline.Trim(), Environment.NewLine);
}
buildstr.Append("</ul>" + Environment.NewLine);
Console.WriteLine(buildstr.ToString());
Which gives this output
<ul>
<li>1. The <title> element</li>
<li>defines a title in the browser toolbar</li>
<li>provides a title for the page when it is added to favorites</li>
<li>displays a title for the page in search-engine results</li>
<li>2. CSS can be added to HTML in the following ways</li>
<li>Inline - using the style attribute in HTML elements</li>
<li>Internal - using the <style> element in the <head> section</li>
<li>External - using an external CSS file</li>
</ul>