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:

<number>12.3
<operator> *
<number> 34
<operator> +
<number> 4
<operator> *
<number> 5
<operator> -
<number> 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!!

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.

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!!

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!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.