4 Replies - 2175 Views - Last Post: 22 March 2013 - 01:52 AM Rate Topic: -----

#1 jayveeeeeee  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 66
  • Joined: 27-September 12

regex

Posted 18 March 2013 - 04:05 AM

can anyone can explain how this code(method) work
                Dim wordcount As Integer = Regex.Matches(TextBox1.Text, words).Count
the whole code
Imports System.Text.RegularExpressions
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles start.Click
        clear.Enabled = False

        lumabas.Enabled = False
        cancel.Enabled = True
        'Get the input sentence
        ' Dim INPUT As String
        '   Input = InputBox("Enter Your String ")
        If TextBox1.Text = String.Empty Then
            MsgBox("Please Enter A String", vbInformation + vbOKOnly, "String Input")
        Else
            'Split the sentence into word
            Dim splitstring() As String = TextBox1.Text.Split(CChar(" "))
            'OR  DIM SPLITSTRING () AS STRING = TEXTBOX1.TEXT.SPLOT("")
            'make listbox 2 display words sorted in alphabetical order

            For Each words As String In splitstring
                'Count how many times the word is in the sentence
                Dim wordcount As Integer = Regex.Matches(TextBox1.Text, words).Count
                'PAG TINANGAL ANG COUNT CANNOT BE CONVERTED INTO INTEGER 


                'string input letter 
                ListBox3.Items.Add(words)
                'string will become number 
                ListBox1.Items.Add(words.Length)
                'count the repeated word 
                ListBox2.Items.Add(wordcount.ToString)

            Next

        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear.Click
        ListBox1.Items.Clear()
        ListBox2.Items.Clear()
        ListBox3.Items.Clear()
        TextBox1.Text = String.Empty

    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: regex

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3197
  • View blog
  • Posts: 10,710
  • Joined: 12-December 12

Re: regex

Posted 18 March 2013 - 04:23 AM

Have you read the MSDN docs or searched on Google?

Dim wordcount As Integer = Regex.Matches(TextBox1.Text, words).Count

Regex.Matches:

Quote

Searches an input string for all occurrences of a regular expression and returns all the matches.

The statement will find all occurrences of the particular word in TextBox1.Text, count them, and store this number in wordcount.

If you don't know what a Regular Expression (regex) is then you'll need to look this up as well.
Was This Post Helpful? 0
  • +
  • -

#3 IronRazer  Icon User is online

  • D.I.C Addict

Reputation: 201
  • View blog
  • Posts: 707
  • Joined: 01-February 13

Re: regex

Posted 18 March 2013 - 04:35 AM

Hi jayveeeeeee,
The first part of the line is just declaring wordcount as an integer so that a number can be stored in it.
Dim wordcount As Integer =


The second part of the code RegEx.Matches(TextBox1.Text, words) Looks for any words that match (words) in the (TextBox1.Text) and by using the (.Count) on the end of it tells the command to return the count of the words that match. So (wordcount) gets assigned the number of words in Textbox1 that match whatever (words) is.
Regex.Matches(TextBox1.Text, words).Count


Here is a Link to msdn for Regex.Match Method (String, String).
:bigsmile:
Was This Post Helpful? 0
  • +
  • -

#4 jayveeeeeee  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 66
  • Joined: 27-September 12

Re: regex

Posted 22 March 2013 - 01:32 AM

Thank You For Your Time and thank you very much,, sorry if i ask u a lot question because i want to get the 10 out of 10 rate in grade for our defense...and this is my way to learn ask a lot of question to the pro
Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,411
  • Joined: 29-May 08

Re: regex

Posted 22 March 2013 - 01:52 AM

A pro does the research themselves.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1