程序处理后输出结果换行符丢失怎么解决
发布时间: 2013-08-09 15:16:24 作者: rapoo
【求助】程序处理后输出结果换行符丢失如何解决
本帖最后由 zyz516130383 于 2013-08-02 13:13:02 编辑 http://pan.baidu.com/share/link?shareid=4140727020&uk=1459936912
↑这是下载地址。我用的工具是VS2010,请问下程序处理过后换行符丢失怎么解决?
比如:
da 20 da 10
da 1 处理后应该是: da 1 现在却变成了da 10 da 1 da 15
da 31 da 15
换行符直接不见了请问如何解决?
[解决办法]
char[] sp = { ' ', '\t', '\n', '\r' };
string[] temps = content.Split(sp);
就表示它会按照空格/TAB/换行符进行字符串拆分,你改为char[] sp = { ' ', '\t'}应该就可以看出效果了,只是你的需求很奇特,它原本的拆分方式很合理的。
[解决办法]string[] temps = content.Split(sp);
改成:
string[] temps = Regex.Split(content, @"([ \t\n\r])");
foreach (string temp in temps)
content += temp + " ";
改成:
foreach (string temp in temps)
content += temp;