开发者

String parser in C and C#

开发者 https://www.devze.com 2023-01-15 10:11 出处:网络
I have a string, \"-(1-cos(R*T))/R\", that I need to be evaluated in both C and C#. Is there a library, or a quick way to do this? Or do I need to writ开发者_如何学运维e my own parser?

I have a string, "-(1-cos(R*T))/R", that I need to be evaluated in both C and C#. Is there a library, or a quick way to do this? Or do I need to writ开发者_如何学运维e my own parser?

I'm also assuming that R and T are known and are local variables.


There's one on CodeProject that's certainly worth a look. There's also a blog post from 2007 that has a list (and benchmarks) of a number, including a half dozen or so that are free.


This is in C#

 private void MyMethod1()
        {
            string s = "-(1-cos(R*T))/R";
            float R = 1;
            float T = 1;
            double doutput =-(1-Math.Cos(R*T))/(R);
        }


No, there is no eval() in C.


Regular Expression is what you are looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消