我有两个文件路径作为字符串:
const filePath = "reports/cucumber/7/cucumber/sample/json/login.json"
const reportFolder = "reports/cucumber/7/cucumber/sample"
我需要比较这两个,然后得到输出为
/json/login.json
我该怎么做?
您也可以使用String.replace()
来获得差异:
const filePath = "reports/cucumber/7/cucumber/sample/json/login.json"
const reportFolder = "reports/cucumber/7/cucumber/sample"
const diff = filePath.replace(reportFolder, '');
console.log('Diff:', diff)
const filePath = "reports/cucumber/7/cucumber/sample/json/login.json"
const reportFolder = "reports/cucumber/7/cucumber/sample"
const diff = (diffMe, diffBy) => diffMe.split(diffBy).join('')
const C = diff(filePath, reportFolder)
console.log(C)