c# - Create Regex search instance for each item in a string -
using visual.web.developer.2010.express; n00b here,
how make search instance each line of text in string1? want search string2 in it's entirety see if contains 1 line of text in string1's search instance every item in string2. both string1 , string2 have lines of text separated '\n'. there obvious way this? suggested regex, how incorporate regex find , print out matches in string2 each item in string1.. there more few instances in string2 relate single item in string1.
a few in string1:
part_numbers
1017foo
1121bar
etc...
a few in string2:
supercola 51661017fooaindo
dasudama c 89891121barblo5w
etc...
probably going figure out later, want them formatted this, fyi
1017foo matched:
supercola 51661017fooaindo
+another 1 1017foo matched+
etc...
in advance!
looking pointers in right direction, on methods should using
your requirements written don't require regular expressions didn't use them. should able incorporate them pretty if need to...
string partnumbers = @"1017foo 1121bar somethingelse"; string searchtext = @"supercola 51661017fooaindo dasudama c 89891121barblo5w"; string[] searchterms = partnumbers.split('\n'); string[] searchedlines = searchtext.split('\n'); stringbuilder output = new stringbuilder(); foreach(string searchterm in searchterms){ int matchcount = 0; output.appendline(string.format("for term: {0}", searchterm.trim())); foreach(string searchedline in searchedlines){ if(searchedline.trim().tolower().contains(searchterm.trim().tolower())){ output.appendline(searchedline.trim()); matchcount++; } } if(matchcount == 0){ output.appendline("there no match"); } output.appendline("== end of search =="); } console.writeline(output.tostring());
Comments
Post a Comment