Last active
August 29, 2015 14:18
-
-
Save jsonmez/3c2d3deb8ccc9b2b049d to your computer and use it in GitHub Desktop.
Removing comments example: before
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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