【发布时间】:2014-12-15 23:23:47
【问题描述】:
我正在创建这个简短的桌面应用程序,它可以清除多余的空格或从字符串中输入。您知道,有时当您从 pdf 复制文本以放置它时,例如在谷歌翻译器上比你粘贴,文本就像在带有额外输入或空格的行中刹车。所以我为我创建了这个简单的应用程序,它清理了这些多余的空间并将其输入并加入到一个段落中。
这是我调试错误的代码和评论:
List<string> content = new List<string>();
TextRange textRange = new TextRange(RichTb1.Document.ContentStart, RichTb1.Document.ContentEnd);
TextRange joiniText = new TextRange(RichTb2.Document.ContentStart, RichTb2.Document.ContentEnd);
string[] lines = textRange.Text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
//to here is all ok, you can see in my List "lines" all lines that I have put it on RichTb1
content.AddRange(lines);
//this is just validation if entry in RichTb1 is empty (if not empty procede with action)
string match1 = content.ElementAt(0);
if (!string.IsNullOrWhiteSpace(match1))
{
//**Here is problem, it clean all spaces or enters - empty lines, but also it clean not empty lines it also cleans some strings, see example down**
content = content.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
joinText.Text = content.Aggregate((i, j) => i + " " + j);
}
这是它所做的结果,例如你放了一些这样的随机文本:
"Chapter 4 illustrates the growing recognition
of
the
benefits
of
community
management
of
natural
resources.
To
ensure
that
such
approaches
do
not
exclude
poor
people,
**women,
the
elderly**
and
other
marginalized
groups,
governments
and
other
organizations
that
sponsor
community-based
projects
need
to
involve
all
groups
in
decision-making
and
implementation."
我的应用程序的结果是这样的:
"Chapter 4 illustrates the growing recognition of the benefits community management natural resources. To ensure that such approaches do not exclude poor people, **women, elderly** and other marginalized groups, governments organizations sponsor community-based projects need to involve all groups in decision-making implementation."
如您所见(这只是示例),它只是清除了一些不应该出现的单词,在上面的示例(强文本)中,您可以看到,单词 "the" 丢失了,在第一个文本中有这个单词。同样在我的台词中,我可以看到这个词。但是当行出现问题时,它会清除不应该出现的字符串(单词)。
任何想法是什么问题...在此先感谢
【问题讨论】:
-
DISTINCT只允许返回不同的单词... -
@MichaelMcGriff 感谢您的回复,您建议使用什么。
-
只需删除不同的。为什么你认为这是必要的?
-
am :) 你能把它回答一下,这样我就可以投票了,这是一个解决方案......