Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting string expression to Integer Value using C# [duplicate]

Tags:

string

c#

integer

Sorry if this question is answered already, but I didn't find a suitable answer. I am having a string expression in C# which I need to convert to an int or decimal value.

For example:

string strExp = "10+20+30";

the output should be 60.

how shall I do that???

like image 933
Jankhana Avatar asked Apr 09 '10 13:04

Jankhana


People also ask

Can you convert a string to an int in C?

In C, the atoi() function converts a string to an integer.

What is atoi () in C?

Description. The atoi() function converts a character string to an integer value. The input string is a sequence of characters that can be interpreted as a numeric value of the specified return type. The function stops reading the input string at the first character that it cannot recognize as part of a number.

What is Strtol () in C?

The strtol library function in C converts a string to a long integer. The function works by ignoring any whitespace at the beginning of the string, converting the next characters into a long integer, and stopping when it comes across the first non-integer character.


1 Answers

Use NCalc : stable, simple, and powerful

like image 56
Catalin DICU Avatar answered Sep 26 '22 14:09

Catalin DICU