Skip to content

Instantly share code, notes, and snippets.

@jsonmez
Last active August 29, 2015 14:18
Show Gist options
  • Save jsonmez/3c2d3deb8ccc9b2b049d to your computer and use it in GitHub Desktop.
Save jsonmez/3c2d3deb8ccc9b2b049d to your computer and use it in GitHub Desktop.
Removing comments example: before
internal static void SplitDirectoryFile(string path, out string directory, out string file)
{
directory = null;
file = null;
// assumes a validated full path
if (path != null)
{
int length = path.Length;
int rootLength = GetRootLength(path);
// ignore a trailing slash
if (length > rootLength && EndsInDirectorySeparator(path))
length--;
// find the pivot index between end of string and root
for (int pivot = length - 1; pivot >= rootLength; pivot--)
{
if (IsDirectorySeparator(path[pivot]))
{
directory = path.Substring(0, pivot);
file = path.Substring(pivot + 1, length - pivot - 1);
return;
}
}
// no pivot, return just the trimmed directory
directory = path.Substring(0, length);
}
return;
}
public void Split()
{
if (validatedFullPath != null)
{
IgnoreTrailingSlash();
FindPivotIndexBetweenEndOfStringAndRoot();
if(!pivotFound)
TrimDirectory();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment