-2

I have a string Saxon Securitie/Logo/horse-logo.jpg_1413458235818 in format "A/B/C"

I want the result as C by removing "A/B/" from the above string and get a result

String C = "horse-logo.jpg_1413458235818"
msrd0
  • 7,816
  • 9
  • 47
  • 82
Davis
  • 310
  • 1
  • 3
  • 14

4 Answers4

5

Try:

  String s = "Saxon Securitie/Logo/horse-logo.jpg_1413458235818";
  String c = s.substring(s.lastIndexOf("/") + 1);
  System.out.println(c);
SMA
  • 36,381
  • 8
  • 49
  • 73
4
String filePath = "Saxon Securitie/Logo/horse-logo.jpg_1413458235818";
String fileName = new File(filePath).getName();

See https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem

Community
  • 1
  • 1
Christoffer Hammarström
  • 27,242
  • 4
  • 49
  • 58
0

You can use String.lastIndexOf to do that :

String path     = "Saxon Securitie/Logo/horse-logo.jpg_1413458235818";
int    index    = path.lastIndexOf("/");
String fileName = index == -1 ? null : path.substring(index + 1);
Dici
  • 25,226
  • 7
  • 41
  • 82
0

I'm not going to give you answer but you could easily use split function in java that you can learn about here. and at first split with space then split with /

Lrrr
  • 4,755
  • 5
  • 41
  • 63