【发布时间】:2011-11-23 02:22:13
【问题描述】:
我需要在最接近 texbox 的第 30 个字符的空间上打断,我得到了很好的答案:
var x = 30;
if (textBox1.Text.Length > x)
{
var index = textBox1.Text.Select((c, i) => new {c, i}).TakeWhile(q => q.i < x).Where(q => q.c == ' ' ).Select(q => q.i).Last();
textBox1.Text = textBox1.Text.Insert(index, Environment.NewLine);
}
唯一的问题是我需要从计数中排除“@A”、“@B”等字符,因为它们用于文本格式。
【问题讨论】:
标签: c# asp.net line-breaks