c# - How to cut out a part of a path? -
i want cut out part of path don't know how. path, use code:
string path = system.io.path.getdirectoryname(fullyqualifiedname); (path = "y:\test\project\bin\debug")
now need first part without "\bin\debug".
how can cut part out of current path?
if know, don't need "\bin\debug" use replace:
path = path.replace("\bin\debug", ""); or
path = path.remove(path.indexof("\bin\debug")); if know, don't need everything, after second \ use this:
path = path.remove(path.lastindexofany(new char[] { '\\' }, path.lastindexof('\\') - 1)); and finally, take many parts, how many want this:
path = string.join(@"\", path.split('\\').take(3)); or skip many parts, how many need:
path = string.join(@"\", path.split('\\').reverse().skip(2).reverse());
Comments
Post a Comment