compiler construction
-
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.
-
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.
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."
-
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."
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 -
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)
NextYour 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."