views:

134

answers:

1

I'm assuming:

String abc = "My Documents/FileName.txt".Split('/')[1]; // is not the quickest way

Is it?

+2  A: 
String abc = "My Documents/FileName.txt";
abc = abc.Substring(abc.LastIndexOf('/') + 1);

This has the following virtues:

  1. there is no slash, in which case it just returns the name, and
  2. there are multiple slashes, in which case it returns just the final component
  3. it creates the fewest number of intermediate objects
lavinio