49,777 Members
2 added today
332,753 Resources
164 added today

All Devdex   All Gurus  

The BODMAS Class - Extracting numbers from string and performing mathematical calculations
Author: Ravichandran J.V.
Rating: Rate this Resource
Visits: 699

Discuss in Newsgroups

using System;
class Bodmas
{
public static string s;
public Bodmas()
{
s=null;
}
public static void Test(string str)
{
char ch=' ';
int ctr=1,plusctr=0,slashctr=0,result=0;
string s1=null,s2=null,s3=null,s4=null;
bool plusSign=false,divSign=false,flag=false;
while (ch!='\n')
{
ch=str[ctr];
if (ch!='('){
if (ch!=')'){
s1+=ch;
}
}
ctr++;
}

s1+='\n';
ctr=0;
while (flag==false){
if (s1[ctr]=='+'){

int plus=s2.ToInt32();
plusSign=true;
plusctr=ctr;
flag=true;
if (s1[ctr]=='-'){
if ( s1[ctr]=='*'){
if (s1[ctr]=='/'){
}
}
}
}
else{
s2+=s1[ctr];
}
ctr++;
}
ctr=plusctr+1;
while (flag==true)
{
if (s1[ctr]=='/'){
slashctr=ctr;
divSign=true;
flag=false;
}
else{
s3+=s1[ctr];
}
ctr++;
}
ctr=slashctr+1;
while (flag==false)
{
if (s1[ctr]=='\n')
{
flag=true;
}
else{
s4+=s1[ctr];
}
ctr++;
}
if (plusSign==true)
{
result=s2.ToInt32()+s3.ToInt32();
}
if (divSign==true)
{
result=result/s4.ToInt32();
}
Console.WriteLine( result);
}
public static void Main()
{
Test("(10+6)/8\n");
}
}


Visit my guru profile

Visitor Comments

Be the first to rate this code sample!

 

Rate this Code Sample






	
	
	



Credit Card Payment Control
Supports over 25 companies
Managed ASP.NET Solution
Direct Processor Support

ASP ArticlesThis category has been added to your weekly newsletter
ASP Web Sites
ADSI & WSH BooksThis category has been added to your weekly newsletter
FREE ComponentsThis category has been added to your weekly newsletter
ASP EventsThis category has been added to your weekly newsletter
ASP HeadlinesThis category has been added to your weekly newsletter

CSharp ArticlesThis category has been added to your weekly newsletter
C# Web SitesThis category has been added to your weekly newsletter

SQL ArticlesThis category has been added to your weekly newsletter
SQL Events
SQL HeadlinesThis category has been added to your weekly newsletter
SQL Jobs

Jobs in CaliforniaThis category has been added to your weekly newsletter

XML ArticlesThis category has been added to your weekly newsletter
XML BooksThis category has been added to your weekly newsletter
XML Web Sites
XML Tutorials

free asp host

"Alex Homer"This search has been added to your weekly newsletter

Edit My Favorites Edit Profile & Favorites

 




Developersdex Home | ASP | C# | SQL | VB | XML | Gurus
Add Your Link | Add Your Code | FAQ | Advertise | Link To Us | Contact Us |
Copyright © 2010 Developersdex™. All rights reserved.