0

Hey, my code fragment is now this:

File fileName = "E:\\Major Project\\FinalLap\\278d.gz.txt.txt";
int index = fileName.toString().lastIndexOf("\\");
filed = fileName.toString().substring(0, index);

And I hope to just get the file's name "278d.gz.txt.txt" after the last instance of "\\" and assign it to variable "filed".
Can anyone tell me what am I doing wrong? Cause I'm still getting the full path.

Thanks a lot!

Edited by jemimaloh: n/a

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by jemimaloh
0

check out the params for substring - you select a substring starting at 0 ending at the last \, but you want one starting at the last \ and extending to the end of the string.

0
filed = fileName.toString().substring(index+1);

got it! thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.