我无法将从 powerpoint 中提取的文本拆分为多行
I can't Split the text extracted from powerpoint into multiple lines
我在文本的形状内提取了一些文本,我将其逐行打印到输出 txt 文件中以供查看,然后再实际执行我需要做的事情。
我遇到的问题是,当我用记事本++打开时,我正在提取的文本我可以看到有一个文本被分成多行,而在普通记事本中它是一大块文本。有没有办法让我检测下一行以拆分字符串?
这是我的代码
int linecounter = 1;
bool isDetailPage = false;
Application pptApplication = new Application();
Presentation pptPresentation = pptApplication.Presentations.Open(file, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
foreach (Slide _slide in pptPresentation.Slides) {
tempOutput.Add("- Parsing Slide " + linecounter);
foreach (Microsoft.Office.Interop.PowerPoint.Shape _shape in _slide.Shapes) {
if(_shape.HasTextFrame == MsoTriState.msoTrue) {
var textFrame = _shape.TextFrame;
if(textFrame.HasText == MsoTriState.msoTrue) {
var textRange = textFrame.TextRange;
Match match = knowldgeSlide.Match(textRange.Text.ToString());
if (match.Success) {
isDetailPage = true;
}
if(isDetailPage) { //ignore other slides
string[] lines = textRange.Text.ToString().Split(
new[] { "\n" },
StringSplitOptions.None
);
int t = 0;
foreach(string x in lines) {
tempOutput.Add("line " + t + ": " + x);
t++;
}
}
}
}
}
isDetailPage = false;
linecounter++;
}
这是从 powerpoint 中提取的文本,我想将其拆分为 5 行字符串。
line 0: Identify the four benefits you gain from convergence and OTN? (Source: Identify the need for the NCS 4000 Series in the OTN Environment)
Virtualized network operations
The scalability
Reduction in transport costs
Flexibility allows operators to employ the technologies
Service contracts
有时 "\r"
除了 "\n"
之外还用作新行。如果文本在 notepad++ 中显示时带有换行符,那么 notepad++ 肯定会注意到某些内容。您可以通过单击查看 > 显示符号 > 显示所有字符来查看每个字符的字符值。当您在记事本++中这样查看它时,找到每行末尾的内容并根据您的 C# 代码中的该字符进行拆分。
在 \r
和 \n
上拆分。
我喜欢这样做:
string[] lines = textRange.Text.ToString().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
我在文本的形状内提取了一些文本,我将其逐行打印到输出 txt 文件中以供查看,然后再实际执行我需要做的事情。
我遇到的问题是,当我用记事本++打开时,我正在提取的文本我可以看到有一个文本被分成多行,而在普通记事本中它是一大块文本。有没有办法让我检测下一行以拆分字符串?
这是我的代码
int linecounter = 1;
bool isDetailPage = false;
Application pptApplication = new Application();
Presentation pptPresentation = pptApplication.Presentations.Open(file, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
foreach (Slide _slide in pptPresentation.Slides) {
tempOutput.Add("- Parsing Slide " + linecounter);
foreach (Microsoft.Office.Interop.PowerPoint.Shape _shape in _slide.Shapes) {
if(_shape.HasTextFrame == MsoTriState.msoTrue) {
var textFrame = _shape.TextFrame;
if(textFrame.HasText == MsoTriState.msoTrue) {
var textRange = textFrame.TextRange;
Match match = knowldgeSlide.Match(textRange.Text.ToString());
if (match.Success) {
isDetailPage = true;
}
if(isDetailPage) { //ignore other slides
string[] lines = textRange.Text.ToString().Split(
new[] { "\n" },
StringSplitOptions.None
);
int t = 0;
foreach(string x in lines) {
tempOutput.Add("line " + t + ": " + x);
t++;
}
}
}
}
}
isDetailPage = false;
linecounter++;
}
这是从 powerpoint 中提取的文本,我想将其拆分为 5 行字符串。
line 0: Identify the four benefits you gain from convergence and OTN? (Source: Identify the need for the NCS 4000 Series in the OTN Environment)
Virtualized network operations
The scalability
Reduction in transport costs
Flexibility allows operators to employ the technologies
Service contracts
有时 "\r"
除了 "\n"
之外还用作新行。如果文本在 notepad++ 中显示时带有换行符,那么 notepad++ 肯定会注意到某些内容。您可以通过单击查看 > 显示符号 > 显示所有字符来查看每个字符的字符值。当您在记事本++中这样查看它时,找到每行末尾的内容并根据您的 C# 代码中的该字符进行拆分。
在 \r
和 \n
上拆分。
我喜欢这样做:
string[] lines = textRange.Text.ToString().Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);