にHTMLは、私は次の文字列を持っていると仮定:分割単語
Hellotoevryone<img height="115" width="150" alt="" src="/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg" />Iamsogladtoseeall.
この文字列は、スペースで区切られていない文字のシーケンスを表し、この文字列に挿入されたHTMLイメージもあります。だから、アイデアは、長さ0の文字として任意のHTMLタグの内容を維持することです
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.
:今私は、それぞれが10文字の長さを有し、単語に文字列を区切りにしたいので、aoutputはする必要があります。
私は、このような方法を書いていたが、それを考慮にhtmlタグを取らない:
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);
}
私は私described.Thanksとして分割を実行するコードを見てみたいです。