Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Remove last element of string

 
Sanj Sharma
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Any one who know how to remove the last element of string.
Say i have string "0000." and i just want to remove "." from it and make it "0000"
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Girish Sharma:
Hi

Any one who know how to remove the last element of string.
Say i have string "0000." and i just want to remove "." from it and make it "0000"



Use substring() method of String class..Referring ur example

 
Sanj Sharma
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Nischal.
 
Sanj Sharma
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will remove all the elements except last i want to remove last element only.
 
newgen pras
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will remove the last element only ....

String str = "0000."
str = str.substring(0,str.length()-1)
System.out.println(str)


Regards
Prasanna
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be sure to test for the case of a zero-length string, otherwise you will get an exception.

Geoffrey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic