Как правильно очищать пробелы или вводы из списка строк в WPF?C#

Место общения программистов C#
Ответить
Anonymous
 Как правильно очищать пробелы или вводы из списка строк в WPF?

Сообщение Anonymous »

Я создаю это короткое настольное приложение, которое очищает дополнительные пространства или входит из строки. Вы знаете, иногда, когда вы копируете текст из PDF, чтобы поместить его, например, В Google Translator, чем вы вставьте, а текст похож на тормоз в строках с дополнительными входами или пространствами. Поэтому я создаю для меня это простое приложение, которое очищает эти дополнительные пространства и входит и присоединяется к одному абзацу.List content = new List();
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);
}
< /code>
Вот результат, что он делает, например, you put some random text like this:

Chapter 4 illustrates the growing recognition

of

the

benefits

of

community

management

of

natural

resources.

to

убедитесь

that

таковые

uppers

do

not

exclude

poor

peopl />women,

the

elderly


and

other

marginalized

groups,

governments

and

other

organizations

that

sponsor

community-based

projects

need

to

involve

all

groups

in

Принятие решений

и

immplementation.
< /blockquote>

Мой результат из моего приложения таково: < /p>

"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."
< /code>

Как вы видите (это просто пример), он просто очищает некоторые слова, которые не должны, в примере выше (сильный текст), вы можете увидеть, это слово «< /code> отсутствует, в первом тексте есть это слово. Также в моих строках я вижу это слово. Но когда строки приходят в проблему, он очищает струны (слова), которые не должны.

Подробнее здесь: https://stackoverflow.com/questions/264 ... ngs-in-wpf
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»