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 Studio
  4. compiler construction

compiler construction

Scheduled Pinned Locked Moved Visual Studio
helptutorialquestion
4 Posts 2 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.
  • M Offline
    M Offline
    magdodo
    wrote on last edited by
    #1

    please I am writing a program to list all the tokens from a sentence and output the result. the program is expected to remove all "space" and "special character(, . + ? / , . * e.t.c)" from the sentence. on running the program t i get the all tokens excluding the space. my problem is i don't know how to make the program exclude the special characters. can someone please help me out? so far this is what i have been able to come up with...

    Dim sentence As string=Txtbox1.text Dim i As integer Dim arr() As string arr=s.split(" ") For i=0 To arr.lenght-1 MsgBox(arr(i)) Next thanks.

    L 1 Reply Last reply
    0
    • M magdodo

      please I am writing a program to list all the tokens from a sentence and output the result. the program is expected to remove all "space" and "special character(, . + ? / , . * e.t.c)" from the sentence. on running the program t i get the all tokens excluding the space. my problem is i don't know how to make the program exclude the special characters. can someone please help me out? so far this is what i have been able to come up with...

      Dim sentence As string=Txtbox1.text Dim i As integer Dim arr() As string arr=s.split(" ") For i=0 To arr.lenght-1 MsgBox(arr(i)) Next thanks.

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

      Kind of sounds like homework to me; however, you can either take a look at the Char class, http://msdn.microsoft.com/en-us/library/system.char.aspx[^], or look for a Regex that will either return allowed characters or match on characters you want to eliminate.

      Comments from work:

      • "Why can't you just do it like everybody else?"
      • "Well, we haven't had any complaints yet."
      • "I just want to get it into production."
      • "It only matters if it’s important to someone who matters."
      M 1 Reply Last reply
      0
      • L Lost User

        Kind of sounds like homework to me; however, you can either take a look at the Char class, http://msdn.microsoft.com/en-us/library/system.char.aspx[^], or look for a Regex that will either return allowed characters or match on characters you want to eliminate.

        Comments from work:

        • "Why can't you just do it like everybody else?"
        • "Well, we haven't had any complaints yet."
        • "I just want to get it into production."
        • "It only matters if it’s important to someone who matters."
        M Offline
        M Offline
        magdodo
        wrote on last edited by
        #3

        thanks a lot for the tip. i tried it but it still only splits the sentence into tokens after every space. what i want is for the program to also split the sentence after every special character. please what is it i am doing wrong? help me out.

        ' The input string.
        Dim sentence As String = TextBox1.Text
        ' Invoke the Regex.Split shared function.
        Dim arr() As String = Regex.Split(sentence, "\s+")
        ' Loop over the elements in the resulting array.
        For Each item As String In arr
        MsgBox(item)
        Next

        L 1 Reply Last reply
        0
        • M magdodo

          thanks a lot for the tip. i tried it but it still only splits the sentence into tokens after every space. what i want is for the program to also split the sentence after every special character. please what is it i am doing wrong? help me out.

          ' The input string.
          Dim sentence As String = TextBox1.Text
          ' Invoke the Regex.Split shared function.
          Dim arr() As String = Regex.Split(sentence, "\s+")
          ' Loop over the elements in the resulting array.
          For Each item As String In arr
          MsgBox(item)
          Next

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

          Your attempt at using the Regex \s is no different than your previous attempt using s.split(" "). You need to find a Regex that returns a value that excludes all of the characters you do not want to included during the output. Try here, http://www.regular-expressions.info/[^], and here, http://regexlib.com/default.aspx[^] You also need to understand that in its most basic description a string is nothing more than an array of characters, http://msdn.microsoft.com/en-us/library/system.char.aspx[^]. There is no need to create an array for something that is already an array.

          Comments from work:

          • "Why can't you just do it like everybody else?"
          • "Well, we haven't had any complaints yet."
          • "I just want to get it into production."
          • "It only matters if it’s important to someone who matters."
          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