vb.net - Getting a list of indexes from a text search in vb2005 -


i running index search on string in rich textbox, have list of keywords need different color in textbox. how run search on string in vb2005 , list of indexes text matched search?

here simple solution. note find word "our" in "four". if not desirable can write eliminate overlapping matches.

private sub page_load(byval sender object, byval e system.eventargs) handles me.load     dim searchtext string = "one 2 3 four"      dim keywords string() = {"one", "four", "our"}      dim wordmatches new generic.list(of wordmatch)      each keyword string in keywords         dim int32 = 0          while <> -1             = searchtext.indexof(keyword, i, system.stringcomparison.ordinalignorecase)              if <> -1                 dim mymatch new wordmatch                 mymatch.charindex =                 mymatch.word = keyword                 wordmatches.add(mymatch)                 += keyword.length             end if         end while     next end sub  private structure wordmatch     public charindex int32     public word string end structure 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -