vb.net - String Compare with special characters -


i want compare 2 strings along hyphen characters , find out correct breaking point

case 1:

dim dictionarystr string = "un-cen-tered" dim textstr string = "uncen-tered" 

result: correct breaking.

case 2:

dim dictionarystr string = "un-cen-tered" dim textstr string = "unce-ntered" 

result: wrong breaking.

first compare 2 words without hyphen make sure have exact same letters @ right place.

then count number of letters on left side of each hyphen (without counting hyphen). if numbers found in textstr found in dictionarystr it's match.

ex: un-cen-tered
un (count 2 letters on left side of first hyphen)
uncen (count 5 letters on left side of second hyphen)

case 1:

dictionarystr: 2, 5
textstr: 5
* 5 contained in previous list, good

case 2:

dictionarystr: 2, 5
textstr: 4
* 4 not in previous list, bad


' list of word hyphen dim dictionarywordswithhyphen new list(of string) ' pre-loaded information dim dictionarywordsinfo new dictionary(of string, list(of integer))  sub main()      ' list of word hyphen     dictionarywordswithhyphen.add("hou-se")     dictionarywordswithhyphen.add("big-hou-se")     dictionarywordswithhyphen.add("some-made-up-word")      ' pre-load information in way easy search on     ' should done once @ begining of program     each word in dictionarywordswithhyphen         dictionarywordsinfo.add(getfullword(word), getlettercount(word))     next      ' test on words     console.writeline(isgoodword("does-not-exists")) ' false     console.writeline(isgoodword("big-hou-se")) ' true     console.writeline(isgoodword("bighou-se")) ' true     console.writeline(isgoodword("big-house")) ' true     console.writeline(isgoodword("bigh-ouse")) ' false     console.readline()  end sub  function getfullword(byval word string) string      return word.replace("-", "") end function  function getlettercount(byval word string) list(of integer)      dim lettercount new list(of integer)     dim split() string = word.split("-")     dim count integer = 0      each section string in split         count += section.length         lettercount.add(count)     next      return lettercount end function  function isgoodword(byval word string) boolean      dim fullword string = getfullword(word)     dim lettercount list(of integer) = getlettercount(word)      ' check if word exists in dictionary     if not dictionarywordsinfo.containskey(fullword)         return false     end if      ' check if letter count exists     each c integer in lettercount         if not dictionarywordsinfo(fullword).contains(c)             ' hyphen @ wrong place             return false         end if     next      return true end function 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -