Large string addition subtraction ?

Posted on 2006-05-14
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

    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 85

    Accepted Solution

    Take a look at this project entitled "C# BigInteger Class":

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    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 (". It will help one to understand clearly the steps to track a lost android phone.

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now