-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,002
  • 9
  • 41
  • 74
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
  • 35,277
  • 7
  • 46
  • 71
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
  • 26,003
  • 4
  • 45
  • 56
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
  • 23,827
  • 6
  • 36
  • 79
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,707
  • 5
  • 41
  • 62