One of Joe J.'s first tasks at his new job was to "clean up" some existing code. We always hope for the best in these situations, but since the code has ended up here, you can tell where this story is going.

The .NET framework has a handy getFileName method, which returns only the file name from a complete path. Since library methods aren't to be trusted, Joe's predecessor decided to use the following routine instead.

 

regex = new Regex (@"\\");
string[] parts = regex.Split(fullPathName.ToString());

foreach (string part in parts)
    result=part.ToString();

 

Now, to be fair, the author of this code may not have known it was possible to index into an array.

 

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!