Assume I have the following string:
Hellotoevryone<img height="115" width="150" alt="" src="/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg" />Iamsogladtoseeall.
This string represents a sequence of chars that are not separated by a space, in this string there is also an html image inserted. Now I want to separate the string into words , each having the length of 10 chars, so the aoutput should be:
1)Hellotoevr
2)yone<img height="115" width="150" alt="" src="/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg" />Iamsog
3)ladtoseeal
4)l.
So the idea is to keep any html tag content as 0 length char.
I had written such a method, but it does not take into consideration the html tags:
public static string EnsureWordLength(this string target, int length)
{
string[] words = target.Split(' ');
for (int i = 0; i < words.Length; i++)
if (words[i].Length > length)
{
var possible = true;
var ord = 1;
do
{
var lengthTmp = length*ord+ord-1;
if (lengthTmp < words[i].Length) words[i] = words[i].Insert(lengthTmp, " ");
else possible = false;
ord++;
} while (possible);
}
return string.Join(" ", words);
}
I would like to see a code that performs the splitting as I described.Thanks.