vb.net - What argument must i pass for this letter instance function -


i need make function counts instance of each letter string z , storing integer array. i'm pretty bad @ working parallel arrays please bear me thanks. far have:

 function letter(byval strtest string) integer()     const intmaxletters integer = 25     dim intletters(intmaxletters) integer     dim value string = "abcdefghijklmnopqrstuvwxyz"     dim chrletters() char = value.tochararray     dim intcounter integer = 0     intcounter = 0 strtest.length - 1         dim c char = strtest.substring(intcounter, 1)         if c >= chrletters(0) , c <= chrletters(25)             **intletters()** += 1         end if     next     return intletters end function 

what argument must pass on intletters add 1 each element? of course intletters(0) representing char , intletters(25) representing z. thank you! also, if use array in more 1 control (like 2 buttons on form) scope should using? thanks!

to answer specific question, index intletters array difference between ascii value of character , ascii value of "a".

i simplify code in couple of ways:

  • rather create string containing lower case letters, can use char.islower method check if character lower case letter.
  • you can loop through characters in string using for/each loop (a string can treated array of characters).

here simplified function.

function letter(strtest string) integer()     dim intletters(25) integer     each c char in strtest 'use strtest.tolower if don't care case of letter         if char.islower(c) intletters(asc(c) - asc("a"c)) += 1     next     return intletters end function 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -