• Post Reply Bookmark Topic Watch Topic
  • New Topic

Separating expression from String into integer.  RSS feed

 
sachin santaji
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a string with value assign like expression.I wanted to take integer value from the string,So please tell me the whole code to solve this problem.

/* I used this method to find but i did't get */

String s="100+300";

for(int i=0;i<s.length();i++)
{
String ds[]=s.split("+");

System.out.println(Integer.parseInt(ds[0]+" "+Integer.parseInt(ds[1])));
}

 
Tim Moores
Saloon Keeper
Posts: 4036
94
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tell me the whole code to solve this problem.

And once we do that, will we get the salary that you earn in your job this month? Or is it a school assignment and we get the credit towards a degree?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sachin santaji wrote:I have a string with value assign like expression.I wanted to take integer value from the string,So please tell me the whole code to solve this problem.

String s="100+300";


I would suggest you read these two pages on our FAQ:

ShowSomeEffort
NotACodeMill

Then come back and try asking your question again, following the advice given.

Alternatively, you can hire someone to do it for you...many folks around here would be glad to quote you a rate of $200/hour, with an 8 hour minimum.
 
dennis deems
Ranch Hand
Posts: 808
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The character + has a special meaning in Regex, so you are required to use the \ character when you are looking for the literal character +. Note that Java itself requires special treatment of the \ character.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!