6 Replies - 19480 Views - Last Post: 06 February 2010 - 09:28 AM Rate Topic: -----

#1 nila  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 156
  • Joined: 05-January 08

how to subtract two strings

Post icon  Posted 18 March 2009 - 09:26 PM

Hi,

I am having a string variable,say

Quote

String a="30"
and another string variable

Quote

String b="1"
.

Now i need to subtract 1 from 30.How do i subtract these two things.
please assist me to do this.

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: how to subtract two strings

#2 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: how to subtract two strings

Posted 18 March 2009 - 09:28 PM

View Postnila, on 18 Mar, 2009 - 10:26 PM, said:

Hi,

I am having a string variable,say

Quote

String a="30"
and another string variable

Quote

String b="1"
.

Now i need to subtract 1 from 30.How do i subtract these two things.
please assist me to do this.

Thanks


Subtract 1 from 30 meaning...29?

Just parse them into integers, subtract them and use a toString() of some sort.
Was This Post Helpful? 0
  • +
  • -

#3 prabhakar.balakrishna  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 21
  • Joined: 17-March 09

Re: how to subtract two strings

Posted 19 March 2009 - 12:46 AM

View PostLocke, on 18 Mar, 2009 - 08:28 PM, said:

View Postnila, on 18 Mar, 2009 - 10:26 PM, said:

Hi,

I am having a string variable,say

Quote

String a="30"
and another string variable

Quote

String b="1"
.

Now i need to subtract 1 from 30.How do i subtract these two things.
please assist me to do this.

Thanks


Subtract 1 from 30 meaning...29?

Just parse them into integers, subtract them and use a toString() of some sort.


It is matter of just parsing to integer and subtract...

String s1 = "29";
String s2 = "1";

int a,b;

a= Integer.parseInt(s1);
b= Integer.parseInt(s2);

now

some int c = a-b;
pleases download and eclipse( it is IDE for java),with help of which you get document help....
Was This Post Helpful? 0

#4 Guest_khan*


Reputation:

Re: how to subtract two strings

Posted 06 February 2010 - 07:42 AM

if i have a string suppose very big more than integer and i want to deal it as a string
e.g
string1 = "1234334343232331";

string2= "4384398747374438374";
answer = string1 - string 2;
How can i do this, Kindly assist me in this
Was This Post Helpful? 0

#5 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,433
  • Joined: 20-September 08

Re: how to subtract two strings

Posted 06 February 2010 - 07:51 AM

Use long or BigInteger. The latter supports numbers of any size
Was This Post Helpful? 1
  • +
  • -

#6 hell32  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 28-October 08

Re: how to subtract two strings

Posted 06 February 2010 - 08:21 AM

View Postkhan, on 06 February 2010 - 06:42 AM, said:

if i have a string suppose very big more than integer and i want to deal it as a string
e.g
string1 = "1234334343232331";

string2= "4384398747374438374";
answer = string1 - string 2;
How can i do this, Kindly assist me in this

Or use Long.parseLong()
Was This Post Helpful? 0
  • +
  • -

#7 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: how to subtract two strings

Posted 06 February 2010 - 09:28 AM

View Posthell32, on 06 February 2010 - 09:21 AM, said:

View Postkhan, on 06 February 2010 - 06:42 AM, said:

if i have a string suppose very big more than integer and i want to deal it as a string
e.g
string1 = "1234334343232331";

string2= "4384398747374438374";
answer = string1 - string 2;
How can i do this, Kindly assist me in this

Or use Long.parseLong()


I think g00se's idea for BigInteger is a decent idea along with Long because mathematical methods are provided as well. The unique thing about this class is that it can be infinitely large because it utilizes an array of bytes.

Here is the API.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1