c# - search multiple words and expressions in a flowdocument wpf -
i'm working on textanalysis tool , love loop through whole text multiple searchexpressions @ same time. right approach? code have 1 search word.
string search = "findme" ; textpointer text = rtfmain.document.contentstart; (textpointer position = rtfmain.document.contentstart; position != null && position.compareto(rtfmain.document.contentend) <= 0; position = position.getnextcontextposition(logicaldirection.forward)) { if (position.compareto(rtfmain.document.contentend) == 0) { break; } string textrun = position.gettextinrun(logicaldirection.forward); stringcomparison stringcomparison = stringcomparison.currentculture; int32 indexinrun = textrun.indexof(search, stringcomparison); if (indexinrun >= 0) { position = position.getpositionatoffset(indexinrun); if (position != null) { textpointer nextpointer = position.getpositionatoffset(search.length); textrange textrange = new textrange(position, nextpointer); textrange.applypropertyvalue(textelement.backgroundproperty, new solidcolorbrush(colors.yellow)); resultlist.add(textrange.text); } } }
what's right approach this? when 1 word has done searching text, need automatically move next word , loop through text again. make list or fill array search words? can guide me in right direction? help.
it time-taking, unproductive search strings without regular expressions.
use regular expressions. powerful tool. start read article - "search strings using regular expressions" - https://msdn.microsoft.com/en-gb/library/ms228595.aspx
Comments
Post a Comment