• Post Reply Bookmark Topic Watch Topic
  • New Topic

string handling  RSS feed

 
priya pratheeeep
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends

i want to delete all the charaters after ".". for example 200.00 to 200

Regards
 
Nicole Schmidt
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try something like:
String mystring = "200.00";
String result = mystring.substring(0, mystring.lastIndexOf("\.");

you must be careful, because "." is a regex expression.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should also check the return value of lastIndexOf. It can return -1 if there is no occurrance, and if you use that -1 in substring you will get a StringIndexOutOfBoundsException.

Also, lastIndexOf does not take a regular expression but an exact string, so there is no need for escaping.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!