954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to use regex or an array to display some output from an arithmetic input?

Hi guys!! I've to make a program that reads an arithmetical sentence from a textbox, e.g 12.3*34+4*5-3 and then on another textbox identify and display what is the content of the first textbox, for example taking the last ex:

If I have this input:
12.3*34+4*5-3

The output should look like this:

12.3
*
34
+
4
*
5
-
3

This program should only read this operators like (+,-,*,/).

I'm have in mind 2 ways of doing it, one with regex and the other taking the first sentence, put it on an array, then trim it, and somehow get the values of the array and identify if it is a number or a decimal number and if it's an operator and the display it.

The difficult part or the part that i can't conceptualize is how to implement it with regex (it should be easier with a regex format than storing it on a array).

Any help will be very appreciated,

Thanks in advanced!!

doomfrawen
Light Poster
28 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

You could create a loop to test each char to see if it is a number or mathmatical operator. Also keep in mind with testing with methods such as IsNumeric it doesnt see decimal points as numeric.

TomW
Posting Whiz
343 posts since Sep 2009
Reputation Points: 84
Solved Threads: 48
 

Well i write this code, this split the sentence and give me the numbers but I can't print 'em on a multiline textbox, I don't know how to use the .lines property.

This is my code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Sentencia As String = TextBox1.Text
        Dim i As Integer
        Dim arryTextBox() As String

        arryTextBox = Sentencia.Split("+", "-", "*", "/")

        For i = 0 To UBound(arryTextBox)
            Dim Array As Object = arryTextBox(i)
            MsgBox(arryTextBox(i)) 'this msgbox works it prints the values of the array
            'TextBox2.Text = Array 'only prints the last value of the array, don't know how to use .lines property
        Next i
    End Sub


BTW, I dont know how to implement the part where i need to store the math operators and then identify em and print the output.

Thanks in advance!!

doomfrawen
Light Poster
28 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

Hi again!!

I just modified the textbox line, to print the outbut without the .lines property..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Sentencia As String = TextBox1.Text
        Dim i As Integer
        Dim arryTextBox() As String

        TextBox2.Clear()

        arryTextBox = Sentencia.Split("+", "-", "*", "/")

        For i = 0 To UBound(arryTextBox)

            Dim Array As String = arryTextBox(i)

            'MsgBox(arryTextBox(i)) 'this msgbox works it prints the values of the array
            TextBox2.Text = TextBox2.Text & Array & vbCrLf
        Next i
        
    End Sub


Now, the part that left the program is to print the operators and print the identifier...

If anyone could help me please :D

Thanks in advance!!

doomfrawen
Light Poster
28 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: