File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Substring() equivalent on numbers

 
sherry cuenco
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Is there an equivalent of substring() on primitive numbers? Given an int = 12345, I would like to extract let's say, 34 from it.
Thanks!
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
You can first convert your number to a String and then use substring.
int i = 12345;
String s = Integer.toString(i);
System.out.println(s.substring(2,3));

But maybe a String would be better from beginning on for your purpose cause this operation makes no sense for a number.
Olli
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1797
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The division (/) and remainder (%) operators can be useful too when doing this sort of thing. And remember that your integer is base 10.
 
sherry cuenco
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your suggestions gentlemen.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic