• Post Reply Bookmark Topic Watch Topic
  • New Topic

extracting some parts from a given string  RSS feed

 
rajkumar soundararajan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose i have a string S="a.png,b.png,c.xlsx";

I need to extract only c.xlsx, how i will do these in java
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The String class has the substring() method to extract parts of a string. It also has the contains(), indexOf(), lastIndexOf(), etc. methods that can be used to determine the parameters to call substring() method with.

In addition to that, it also contains regular expression support via the matches(), replaceFirst(), replaceAll(), and split() methods, which is kinda an overkill to just extract a substring, but useful nonetheless...

Henry
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

To extract part of a string you can use the String classes substring() method or a regex or ... it really depends on how you can identify the sub string you want to extract. For example is it all letters after the last comma, any file name which isn't a png file etc etc.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!