文字列の長さ x よりも長い文字列は、"xxx- xxx" で区切り、改行を作成する必要があります。
例: 20 文字では問題ありませんが、単語に 30 文字がある場合は、18 + "- " + 残りにカットする必要があります。
私は無限ループに陥るこのメソッドを書きました:
string temp = s;
string tempResult = "";
bool found = false;
do
{
found = false;
if (s.Length < lenght) return s;
else
{
//Examine every word to cut everything into words
string[] tempList = temp.Split(' ');
foreach (string temp2 in tempList)
{
//Check every word length now,
if (temp2.Length > lenght)
{
tempResult = tempResult + " " + temp2.Substring(0, lenght - 3) + "- " + temp2.Substring(lenght);
found = true;
}
else
tempResult = tempResult + " " + temp2;
}
if (found) temp = tempResult;
}
} while (found);
return tempResult;