-2

For saving a file on the iPad, I need to get the file name substring (after sites/default/files/) in the following path string:

sites/default/files/243347_TroubleShootingSqlserver20052008.pdf 

How would I do this?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Papu
  • 371
  • 4
  • 8
  • 21
  • you should be a bit more clear, it hard to understand what you want. Do you have a string already? do you need to parse a PDF? Which iOS version? – Roger Jun 22 '12 at 12:55
  • i will advise you an regex BUT here is the best answer http://stackoverflow.com/questions/3613591/finding-a-substring-in-a-nsstring-object – gaussblurinc Jun 22 '12 at 12:55
  • I need the string value after sites/default/files/ in sites/default/files/243347_TroubleShootingSqlserver20052008.pdf – Papu Jun 22 '12 at 12:58

2 Answers2

5

Set your path to NSURL *targetURL. and then

NSString *filename = [[targetURL path] lastPathComponent];
Dhruv
  • 2,153
  • 3
  • 21
  • 45
1
NSArray* pathURL = [path componentsSeparatedByString: @"/"];
NSString* pdfFileName = [pathURL objectAtIndex: [pathURL length]];
Bart
  • 19,692
  • 7
  • 68
  • 77
Sumanth
  • 4,913
  • 1
  • 24
  • 39