VB.Net add count for each -
i have function search count of multiple words in text file.
dim textlog = file.readalltext("d:\1.txt") dim count = regex.matches(textlog, "test1").count dim count1 = regex.matches(textlog, "test2").count label1.text = (count) label4.text = (count1)
it's working fine, want pass words parameter function. , have done this:
dim values string values = words dim wordlist string() = nothing wordlist = values.split(",") dim w string each w in wordlist ''''''' ' search function here ''''''' next w
now want count them, knowing words dynamic, meaning put many words want. in words, how can know how many words being input , find count of them, don't know how return them via function.
not sure regex
effective way such thing, here solution based on own code:
function countwords(filename string, wordlist string()) string(,) dim returnvalue string(,) = new string(wordlist.length, 2) dim textlog = file.readalltext(filename) dim integer = 0 foreach word string in wordlist returnvalue(i,0) = word returnvalue(i,1) = regex.matches(textlog, word).count i+=1 next return returnvalue end function
note: code written directly here, , it's been while since vb.net days, there might mistakes. however, believe concept more important in these kind of answers.
Comments
Post a Comment