[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Large string addition subtraction ?

Posted on 2006-05-14
Medium Priority
Last Modified: 2008-03-06
I have two very long strings (150-250 digits) I need to perform math addition subtraction.

string a = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
string b = "222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222";
string c = "33333333333333333333";

string Finished = a - b + c;

These are the longest/largest numbers I've ever worked with, so I don't know if I should covert them before processing math.

I recieve this compile error:  Operator '-' cannot be applied to operands of type 'string' and 'string'      
Question by:kvnsdr
LVL 44

Expert Comment

ID: 16678794
in 'addition', with C# the + operator, operating on strings does CONCATENATION, not 'addition' - with strings, even if made up of digits, the Strings will be APPENDED, not converted to numbers and the ADDED.


string b = "222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222";
string c = "33333333333333333333";

b+c = "22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222233333333333333333333"



I do not know of any 'native' C# workspaces that can deal with 150 -250 digit INTEGERS.  What are you doing that requires the use of such large numbers?


LVL 86

Accepted Solution

Mike Tomlinson earned 375 total points
ID: 16678821
Take a look at this project entitled "C# BigInteger Class":

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question