C# 写入文本如何自动换行

string Content = "One major sticking point is a provision that would allow Americans to buy a federal-run insurance plan if their state allows it. Moderates say they worry the so-called public option will become a huge and costly entitlement program and that other requirements in the bill could cripple businesses.";

如何让上面的Content变量保存到一个文本文件里,且每隔40个字符自动换行:如果是空格, 就直接另起一行, 如果是单词就在39个字符后加一个连接符(-).
类似于:
My Name is Alex, th-
is is a reply that
for the purpose of
solving a text for-
matting issue.

第一行,this之间加一个"-"然后换行
第二行和第三行空格, 直接换行.
最后一行没有超过字符,直接换行.

保存文件已经实现,但是这个自动换行,搞了N就都不对.
1L不懂别乱回答.
//
目前还没有一个能用的. xuzicn也不能用

//xuzicn,你运行小郭不能满足需求.

string Content = "One major sticking point is a provision that would allow Americans to buy a federal-run insurance plan if their state allows it. Moderates say they worry the so-called public option will become a huge and costly entitlement program and that other requirements in the bill could cripple businesses.";

StringBuilder builder = new StringBuilder();
while (Content.Length > 40)
{
builder.Append(Content.Substring(0, 39));
if (Content[39].Equals(' '))
{
builder.Append("\r\n");
Content = Content.Substring(40);
}
else
{
builder.Append("-\r\n");
Content = Content.Substring(39);
}
}
builder.Append(Content);

string result = builder.ToString();

怎么不能用,我自己试过了,结果是正确的,有错误消息么
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-24
价格换行符号

Constants.vbCrLf
第2个回答  2009-11-24
要自己设置换行的
第3个回答  2009-11-24
你要不要试下FlowDocument
相似回答
大家正在搜