Link to home
Start Free TrialLog in
Avatar of kvnsdr
kvnsdr

asked on

Large string addition subtraction ?

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'      
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

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


ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial