javascript
含有运算符的STRING得到计算结果,类似JS的EVAL
不知道在哪看見一個人寫過一個算法的,然后求得結果,不過我又看到一個人用
Dim xmlD As System.Xml.XmlDocument
??????? Dim xmlP As System.Xml.XPath.XPathNavigator
類似前臺寫的EVAL就能得到結果。
后臺方法計算,非常好,
寫一了一個,參考:
Private Function CalculateString(ByVal str As String) As Single
??????? Dim xmlD As System.Xml.XmlDocument
??????? Dim xmlP As System.Xml.XPath.XPathNavigator
??????? Try
??????????? xmlD = New System.Xml.XmlDocument
??????????? xmlP = xmlD.CreateNavigator
??????????? Return xmlP.Evaluate(str)
??????? Catch ex As Exception
??????????? Return 0
??????? End Try
??? End Function
例:STR=“8*9 —23 + 45/5”
STR=CalculateString(STR)
結果:STR=58
from: csdn
轉載于:https://www.cnblogs.com/chinaver2002/archive/2005/10/08/249967.html
總結
以上是生活随笔為你收集整理的含有运算符的STRING得到计算结果,类似JS的EVAL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: GIS应对新挑战——空间信息网格技术探寻
- 下一篇: JavaScript 图片滑动切换效果