Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. how to count letters appeared?

how to count letters appeared?

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mijan
    wrote on last edited by
    #1

    How to count freqency of letters appeared in a textbox as input?Let say we type 'I believe', thus the code should count how many each letter appears and also in percentage. e.g. Letter 'E', Frequency = 3, percentage = 0.3 % (out of all letters) Any code example on this? thank you~ mijan

    C 1 Reply Last reply
    0
    • M mijan

      How to count freqency of letters appeared in a textbox as input?Let say we type 'I believe', thus the code should count how many each letter appears and also in percentage. e.g. Letter 'E', Frequency = 3, percentage = 0.3 % (out of all letters) Any code example on this? thank you~ mijan

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      mijan wrote:

      How to count freqency of letters appeared in a textbox as input

      Homework question? How do you think the problem would be solved? Here are some highlevel hints: Create some way to map letters to a count. Iterate through the string and add one to the relevant count for each letter you encounter. Add one also to an total counter (so you know how many letters there are in total, so you can work out the percentage) When you finish the iteration of the string, iterate through the map and output the frequency of each letter and its percentage (by the way, you need to work on that calculation as the letter 'E' occurs 37.5% of the time, not 0.3%) If you have a problem on any particluar aspect, show us what you tried and then we can help you fix it. ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

      M 1 Reply Last reply
      0
      • C Colin Angus Mackay

        mijan wrote:

        How to count freqency of letters appeared in a textbox as input

        Homework question? How do you think the problem would be solved? Here are some highlevel hints: Create some way to map letters to a count. Iterate through the string and add one to the relevant count for each letter you encounter. Add one also to an total counter (so you know how many letters there are in total, so you can work out the percentage) When you finish the iteration of the string, iterate through the map and output the frequency of each letter and its percentage (by the way, you need to work on that calculation as the letter 'E' occurs 37.5% of the time, not 0.3%) If you have a problem on any particluar aspect, show us what you tried and then we can help you fix it. ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

        M Offline
        M Offline
        mijan
        wrote on last edited by
        #3

        I've tried using javascript, which kind of easier.I only tried out two letter which 'a' and 'b'..how can i proceed until 'z' in much easier way? var letter, length, total, percent; total = 0; total1 = 0; letter = window.prompt('Please enter a letter', ''); length = letter.length; var my_array = letter.split(""); for(var i=0;i<length;i++){ if( my_array[i] == 'a' ){ total++; percent = total/length * 100; } if (my_array[i] == 'b' ) { total1++; } } document.write('The number of \'a\'s you have input is ' + percent) document.write( 'The number of \'b\'s you have input is ' + total1) mijan

        C 1 Reply Last reply
        0
        • M mijan

          I've tried using javascript, which kind of easier.I only tried out two letter which 'a' and 'b'..how can i proceed until 'z' in much easier way? var letter, length, total, percent; total = 0; total1 = 0; letter = window.prompt('Please enter a letter', ''); length = letter.length; var my_array = letter.split(""); for(var i=0;i<length;i++){ if( my_array[i] == 'a' ){ total++; percent = total/length * 100; } if (my_array[i] == 'b' ) { total1++; } } document.write('The number of \'a\'s you have input is ' + percent) document.write( 'The number of \'b\'s you have input is ' + total1) mijan

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          mijan wrote:

          I've tried using javascript

          Given that this is the Visual Basic.NET forum, I would have expected you to be using that. Anyway, did you think of using an array to hold the totals in? Create an array with 26 elements starting each at 0. item[0] represents A; item[1] represents B; and so on........ ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more? -- modified at 11:21 Thursday 2nd March, 2006

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups