|
-
Apr 20th, 2004, 08:04 PM
#1
Thread Starter
New Member
evaluating the contents of a string
My app takes in a string from a text box which is of course located on a form.
The contents of the string will be some form of expression statement
EG (A*B)+(C/D)
Once the user has entered their expression into the textbox and pressed a control button I want to be able to go though the string and split the contents into chars, oprators(*,+,-,/) and the parentheses.
Is split the best way to do this? Ive been playing around with it and can't seem to find a way of picking out all chars (I could by divining a list of chars but that would take forever)
Any ideas
-
Apr 20th, 2004, 08:18 PM
#2
I wonder how many charact
So using the example expression you gave:
You want....
'EGABCD'
'()()'
'*+/'
?
-
Apr 20th, 2004, 08:28 PM
#3
Thread Starter
New Member
-
Apr 20th, 2004, 09:38 PM
#4
I wonder how many charact
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = TextBox1.Text
Dim characters As New System.Text.StringBuilder(15)
Dim paranthesis As New System.Text.StringBuilder(10)
Dim operators As New System.Text.StringBuilder(10)
Dim c As Char
For i As Integer = 0 To s.Length - 1
c = s.Chars(i)
If Char.IsLetterOrDigit(c) Then characters.Append(c)
If Char.IsPunctuation(c) Then
If Not (c = "(" Or c = ")") Then
operators.Append(c)
Else
paranthesis.Append(c)
End If
End If
If Char.IsSymbol(c) Then operators.Append(c)
Next
Debug.WriteLine("characters: " & characters.ToString)
Debug.WriteLine(Environment.NewLine)
Debug.WriteLine("paranthesis: " & paranthesis.ToString)
Debug.WriteLine(Environment.NewLine)
Debug.WriteLine("operators: " & operators.ToString)
End Sub
-
Apr 20th, 2004, 09:44 PM
#5
Thread Starter
New Member
that is wicked - It never crossed my mind to use the char classes methods! thanks for the point in the right direction !-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|