c# - How can we remove certain folder name from the path and return new path? -
i have path:
"c:\\users\\dev\\test\\testresults\\config\\report.xml"
i need check if path has folder "testresults", if has need remove , return new path as
"c:\\users\\dev\\test\\config\\report.xml"
i know can achieve using trim , split. make sure pick right choice. best way of achieving this?
any appriciated.
i not use string replace method in case. why?
e.g. :
string path = "c:\\users1\\users2\\users122\\users13\\users133\\filename.xml"; path = path.replace("\\testresults", string.empty); // "c:\users222333\filename.xml"
that not expected.
so how fix this,
path = string.join(path.directoryseparatorchar.tostring(), path.split(path.directoryseparatorchar).where(x=> x!="users1").toarray())); //c:\users2\users122\users13\users133\filename.xml
Comments
Post a Comment