如何使用单词拆分段落

时间:2015-04-24 20:04:36

标签: c# string split docx

我的问题是,您如何将此段落分为两个字符串? A部分和B部分?我正在使用DocX dll从word文档中读取它。请记住,文字可能会改变。完全停止可能不存在。但这些段落总是按照a,b,c等部分划分....谢谢!

“A部分如此接近,无论多远。从内心深处都是如此。永远相信我们是谁。没有别的事情重要.Part B从未以这种方式打开自己。 生命是我们的,我们按照自己的方式生活。所有这些话我不仅仅是说。而且没有其他事情重要“

1 个答案:

答案 0 :(得分:0)

如果要在A部分,B部分等进行除法,您可以使用正则表达式将段落拆分为行。

string para = "Part A So close no matter how far. Couldn't be much more from the heart.Forever trusting who we are.And nothing else matters.Part B Never opened myself this way. Life is ours, we live it our way.All these words I don't just say.And nothing else matters";

Regex regex = new Regex("Part [A-Z] ", RegexOptions.IgnoreCase);
string[] lines = regex.Split(para).Where(s => s != String.Empty).ToArray();
相关问题