字符串的数值输出 [英] Numeric Output from string
本文介绍了字符串的数值输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以在vb.net中从(5000 + 400-300)* 12/100"获取输出,但输出应为数字格式,而不是字符串格式.
输出应为612
我怎么才能得到它,因为数组在这里不能正常工作.
Can we get output from "(5000+400-300)*12/100" in vb.net but output should be in numeric format not string format.
Output should be 612
How can i get it bacause array is niot working here.
推荐答案
您需要计算表达式.看一下:运行时C#表达式评估器 [
You need to evaluate the expression. Have a look at this: Runtime C# Expression Evaluator[^] - it''s in C#, but all the principles hold the same for VB.
有两种方法,
1. 创建函数以解析字符串&评估它,例如运行时C#表达式评估器 [
there are 2 ways,
1. create function to resolve string & evalute it e.g. Runtime C# Expression Evaluator[^] as given in solution 1
2. if you are using sql server also, then
equ= "(5000+400-300)*12/100"
cmd.commandtext="select " & equ
dim ans=cmd.executescalar()
祝您编程愉快!
:)
Happy coding!
:)
我的问题已解决.解决方案是您必须为此创建一个函数(选择"5000 + 1000").接受该字符串并进行计算,然后以数字格式返回值.
My question is solved .the solution is you have to make a function for like this (select ''5000+1000''). which accept this string and calculate it then return value to you in numeric format.
这篇关于字符串的数值输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文