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
  1. Home
  2. General Programming
  3. Visual Basic
  4. Counting the Occurence of each letter in a textbox

Counting the Occurence of each letter in a textbox

Scheduled Pinned Locked Moved Visual Basic
tutorialcsharphelp
8 Posts 6 Posters 0 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.
  • T Offline
    T Offline
    tan873
    wrote on last edited by
    #1

    HI I NEED HELP ABOUT COUNTING AN OCCURRENCE OF EACH LETTER IN A TEXTBOX FOR EXAMPLE I HAVE 2 TEXTBOX IN TEXTBOX1 I INPUT THE WORD "HELLO WORLD" THEN WHEN I CLICK BUTTON 1 THEN IT DISPLAY IN TEXTBOX2 LIKE THIS: 1H 1E 3L 2O 1W 1R 1D 1R IT REVERSE AS H1 E1 L3 O2 W1 R1 T1 AS LONG AS IT DISPLAY... THANKS IN ADVANCE I'M NEW IN VB.NET AND I DONT KNOW HOW TO DO THAT...

    C S L 3 Replies Last reply
    0
    • T tan873

      HI I NEED HELP ABOUT COUNTING AN OCCURRENCE OF EACH LETTER IN A TEXTBOX FOR EXAMPLE I HAVE 2 TEXTBOX IN TEXTBOX1 I INPUT THE WORD "HELLO WORLD" THEN WHEN I CLICK BUTTON 1 THEN IT DISPLAY IN TEXTBOX2 LIKE THIS: 1H 1E 3L 2O 1W 1R 1D 1R IT REVERSE AS H1 E1 L3 O2 W1 R1 T1 AS LONG AS IT DISPLAY... THANKS IN ADVANCE I'M NEW IN VB.NET AND I DONT KNOW HOW TO DO THAT...

      C Offline
      C Offline
      Chandrasekharan P
      wrote on last edited by
      #2

      Maybe this link will help you [^] And Read the Guidelines before you post your thread. The 8th Point.

      Every new day is another chance to change your life.

      1 Reply Last reply
      0
      • T tan873

        HI I NEED HELP ABOUT COUNTING AN OCCURRENCE OF EACH LETTER IN A TEXTBOX FOR EXAMPLE I HAVE 2 TEXTBOX IN TEXTBOX1 I INPUT THE WORD "HELLO WORLD" THEN WHEN I CLICK BUTTON 1 THEN IT DISPLAY IN TEXTBOX2 LIKE THIS: 1H 1E 3L 2O 1W 1R 1D 1R IT REVERSE AS H1 E1 L3 O2 W1 R1 T1 AS LONG AS IT DISPLAY... THANKS IN ADVANCE I'M NEW IN VB.NET AND I DONT KNOW HOW TO DO THAT...

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        Here is a quick / rough way that I would count the characters in a string

            Dim s As Char() = TextBox1.Text.ToCharArray
            Dim p As New Dictionary(Of Char, integer)
        
            For Each chars As Char In s
                'ignore the spaces
                If Not chars = " " Then
                    'count the occurances of the character
                    Dim i As Integer = s.Count(Function(r) r = chars)
        
                    'if the letter is not in the dictonary
                    If Not p.ContainsKey(chars) = True Then
                        p.Add(chars, i)
                    End If
                End If
            Next
        

        Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

        D 1 Reply Last reply
        0
        • T tan873

          HI I NEED HELP ABOUT COUNTING AN OCCURRENCE OF EACH LETTER IN A TEXTBOX FOR EXAMPLE I HAVE 2 TEXTBOX IN TEXTBOX1 I INPUT THE WORD "HELLO WORLD" THEN WHEN I CLICK BUTTON 1 THEN IT DISPLAY IN TEXTBOX2 LIKE THIS: 1H 1E 3L 2O 1W 1R 1D 1R IT REVERSE AS H1 E1 L3 O2 W1 R1 T1 AS LONG AS IT DISPLAY... THANKS IN ADVANCE I'M NEW IN VB.NET AND I DONT KNOW HOW TO DO THAT...

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Please do not scream at me. Thank you.

          Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

          R 1 Reply Last reply
          0
          • L Lost User

            Please do not scream at me. Thank you.

            Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

            R Offline
            R Offline
            RobCroll
            wrote on last edited by
            #5

            How do you know that, VB programmers aren't case-sensitive ;P

            "You get that on the big jobs."

            L 1 Reply Last reply
            0
            • R RobCroll

              How do you know that, VB programmers aren't case-sensitive ;P

              "You get that on the big jobs."

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              RobCroll wrote:

              VB programmers

              I would only tolerate it if my "option strict" was on.

              Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

              1 Reply Last reply
              0
              • S Simon_Whale

                Here is a quick / rough way that I would count the characters in a string

                    Dim s As Char() = TextBox1.Text.ToCharArray
                    Dim p As New Dictionary(Of Char, integer)
                
                    For Each chars As Char In s
                        'ignore the spaces
                        If Not chars = " " Then
                            'count the occurances of the character
                            Dim i As Integer = s.Count(Function(r) r = chars)
                
                            'if the letter is not in the dictonary
                            If Not p.ContainsKey(chars) = True Then
                                p.Add(chars, i)
                            End If
                        End If
                    Next
                

                Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                Your creating a Dictionary of String to store an Integer?

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                S 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Your creating a Dictionary of String to store an Integer?

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  S Offline
                  S Offline
                  Simon_Whale
                  wrote on last edited by
                  #8

                  Oh crap! It was ment too be an integer

                  Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

                  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