Solved

# Large string addition subtraction ?

Posted on 2006-05-14
862 Views
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'
0
Question by:kvnsdr

LVL 44

Expert Comment

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.

with

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

b+c = "22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222233333333333333333333"

not

"222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222255555555555555555555"

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?

AW

0

LVL 85

Accepted Solution

Take a look at this project entitled "C# BigInteger Class":
http://www.codeproject.com/csharp/biginteger.asp
0

## Featured Post

### Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.