Question: I want to extract the name of a file from a string like this

```
C:\IBM\...\images\custom\fileName.png

```

But

```
[string lastPathComponent];

```

gives me the whole string instead of fileName.png. What am I doing wrong here?

Answer: 
I believe `lastPathComponent` splits based on forward slash "/", your path contains only backslashes "\"

You can try replacing your backslashes:

```
[path stringByReplacingOccurrencesOfString:@"\\" withString:@"/"].lastPathComponent;

```
In addition to michaels answer, you could also do the following. 

```
NSArray *listItems = [string componentsSeparatedByString:@"\\"];
NSString *endOfString = [listItems lastObject];    

```

as long as the string is not an empty or nil string, this will work.