我正在努力extract the path from left to right based on the first match from left to right but only with the Folder name and not with the file name:
string numberToFind = "99999";
string filePath = "\\mydomain.com\TestEnv\MyApp\ImportantFiles\Phase 1\Employee\Folder 1\Folder 1.2\Folder 1.2.1_99999_PayRoll data\Folder 99999\JanSlip.pdf";
int resultIndex = data.LastIndexOf(numberToFind);
if(resultIndex!=-1)
{
data = data.Substring(0,resultIndex);
}
Output - \\mydomain.com\TestEnv\MyApp\ImportantFiles\Phase 1\Employee\Folder 1\Folder 1.2\Folder 1.2.1_
Expected Output :
"\mydomain.com\TestEnv\MyApp\ImportantFiles\Phase 1\Employee\文件夹 1\Folder1.2\文件夹1.2.1_99999_Payroll Data
如你所见,我得到的输出与‘预期输出’不匹配.
请注意,我只想match the numberToFind on the folder level
并根据第一个匹配项从左到右提取路径,但如果在文件夹级别上没有找到匹配项,我想返回整个路径.For eg:
string numberToFind = "99999";
string filePath = "\\mydomain.com\TestEnv\MyApp\ImportantFiles\Phase 1\Employee\Folder 1\Folder 1.2\99999_JunePayslips.pdf";
Expected output : \\mydomain.com\TestEnv\MyApp\ImportantFiles\Phase 1\Employee\Folder 1\Folder 1.2\99999_JunePayslips.pdf