This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes End of the string in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "End of the string in java" Watch "End of the string in java" New topic
Author

End of the string in java

vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
Dear experts,

please inform me how to check the end of the string in java,

as i have one string, which keeps on appending at runtime which mainly takes a file name,

so after it finishes in getting the whole string i can query otherwise it gives me wrong results

for example:


here i have to check : if i enter a file name test.abc



here on splitting the file on .(dot) i have to check if this not the extensio(abc) , if not error other wise no action

so in this case i get a extenstion not equal to abc ( ) as the string it reads in this format like,



so till last option first two times it goes for which is not the desired

please help me how to achieve this.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Uhm, I'm not sure if I really understood the problem but are you trying to check the extension of the filename ??

In that case, use lastIndexOf(".")


JDBCSupport - An easy to use, light-weight JDBC framework -
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3826

Have you checked what the "file1" contains at runtime?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

If you ignore the case you can also simply use the endsWith method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: End of the string in java