如何在每个\n
字符处拆分该字符串,并用;
字符替换,最后将它们放入数组中。在c中剪切字符串#
之后,如果数组中的行长度超过60个字符,则再次分割,只是在char 60之前的最后一个空格处。然后在第二部分仍然长于60时重复?
我的代码是:
var testString = "Lorem Ipsum is simply dummy \n text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, \nwhen an unknown printer took a galley of \n type and scrambled \n it to make a type specimen";
const int maxLength = 60;
string[] lines = testString.Replace("\n", ";").Split(';');
foreach (string line in lines)
{
if (line.Length > maxLength)
{
string[] tooLongLine = line.Split(' ');
}
}
结果:
Lorem存有简直是虚拟;
印刷和排版行业的文字。 Lorem Ipsum已从
自从16世纪以来的行业标准虚拟文本;
当一台未知的打印机拿走一个厨房的时候;
type and scrambled;
它制作一个型号的样本;
你知道你可以只分割'\ n'而不是先做替换。 – juharr
是的,但我需要用\ n替换\ n字符; –
我很困惑..输出不是你所期望的吗? –