vb.net - How can I remove the repeated lines in my output? -
if arrysentence.contains(inputstring) dim index integer = array.indexof(arrysentence, inputstring) until >= arrysentence.getupperbound(0) + 1 dim position integer = index + 1 index = array.indexof(arrysentence, inputstring, position) console.writeline("the word ""{0}"" @ position {1}.", inputstring, position) = + 1 loop
it's done problem output repeats of lines like:
please enter sentence
apple fall apple tree
word apple @ position 2
word apple @ position 6
word apple @ position 2
word apple @ position 6
help!
i not understand reasoning behind loops. want following: search word in array. if exists, print position. otherwise exit. start over.
here how it:
dim index integer = array.indexof(arrysentence, inputstring) while index >= 0 'while word has been found 'output occurrence console.writeline("the word ""{0}"" @ position {1}.", inputstring, index + 1) 'search next occurrence index = array.indexof(arrysentence, inputstring, index + 1) end while
Comments
Post a Comment