Q:

Fastest way to remove all characters between '/' in a String

I have .txt files inside directory
I want to change the name of those .txt files, when saving.
I.e. /root/user/workspace/DataSet/dataset/file0.txt
I have already solved the problem in an inefficient way
for (int i = 0; i < img_n.length(); i++) {
    char a = img_n.charAt(i);

    if (a == '/') {
        c++;
    }

    if (c >= 6) {
        out += a;
    }
}
return out;

I knew the 6 times '/' will come so when c>=6 add char to the new string.
So This is NOT how to remove all '/' in an input string
If you see my code clearly
It is also not taking the chars between '/'.
Therefore the Question is: 
You don't know how many times '/' comes but, you also want to remove the characters between '/'. 
How can I do this more generic and efficient way?

A:

How about this:
int ix = img_n.lastIndexOf('/');
out = ix < 0 ? img_n : img_n.substring(ix+1);

