Friday 15 August 2014

c# - How to correctly clean spaces or enters from list of strings in WPF? -



c# - How to correctly clean spaces or enters from list of strings in WPF? -

i creating short desktop application cleans spaces or enters string. know, when re-create text pdf set e.g. on google translator paste, , text brake in lines enters or spaces. create me simple app, cleans spaces , enters , bring together 1 paragraph.

here code , coment debug mistake:

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 ok, can see in list "lines" lines have set on richtb1 content.addrange(lines); //this validation if entry in richtb1 empty (if not empty procede action) string match1 = content.elementat(0); if (!string.isnullorwhitespace(match1)) { //**here problem, clean spaces or enters - empty lines, clean not empty lines cleans strings, see illustration down** content = content.where(s => !string.isnullorwhitespace(s)).distinct().tolist(); jointext.text = content.aggregate((i, j) => + " " + j); }

here result do, e.g. set random text this:

"chapter 4 illustrates growing recognition of benefits of community management of natural resources. ensure such approaches not exclude poor people, **women, elderly** , other marginalized groups, governments , other organizations sponsor community-based projects need involve groups in decision-making , implementation."

my result app this:

"chapter 4 illustrates growing recognition of benefits community management natural resources. ensure such approaches not exclude poor people, **women, elderly** , other marginalized groups, governments organizations sponsor community-based projects need involve groups in decision-making implementation."

as see (this example) clears words should not, in illustration above (strong text) can see, word "the" missing, in first text there word. in lines can see word. when lines come problem line cleans strings (words) should not.

any ideas problem... in advance

the distinct allowing distinct words returned. remove , should have no farther problem.

see msdn docs here: http://msdn.microsoft.com/en-us/library/system.linq.enumerable.distinct(v=vs.95).aspx

c# wpf string space

No comments:

Post a Comment