Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

another silly question

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If i have a number, make it a string, and then take a sub string of it
i.e
int i=423;
String iVal=""+i;
String subval=iVal.substring(1,2);
I now should have a substring with 4
My question is, i am not sure of the syntax used to "parse" something to something else.
If I want to parse this substring "subval" to an integer I know I do <i>something</i> like this:
int subval=Integer.parseInt(subval);
but I am not sure of the exact syntax
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe,

Are you trying to break the value 423?

Here is an example:


Joyce
[ October 10, 2004: Message edited by: Joyce Lee ]
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

subval = "2"

String character positions start at 0.

substr( firstPosition, lastPosition+1 )

So substr(1,2) selects the second character




Your syntax is fine, but is subval an int or a String?
 
Joe Panully
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic