我正在使用 lodash JS 实用程序 (v4.17.21) 来执行基本修剪功能,如下面的代码所示。
const process = require('process');
const lodash = require('lodash')
var path = "C:/Users/C5317673/repo-caches/cornerstone"
var fileName = "C:/Users/C5317673/repo-caches/cornerstone/CIC/models/advancedreturnsmanagement/FollowUpActivityCodes.cds"
console.log(lodash.trimStart(fileName, path)) //returns IC/models/advancedreturnsmanagement/FollowUpActivityCodes.cds
console.log(fileName.substring(path.length+1)) //returns CIC/models/advancedreturnsmanagement/FollowUpActivityCodes.cds
我很好奇的是,Lodash 的 trimstart 函数会从输出中删除一个额外的字符(我希望它以 CIC 开头)。而常规子字符串选项则可以正常工作。顺便说一句,我只在 Windows 系统上看到过这种情况,例如在 macOS 上没有看到过。
有什么建议吗?
_.trimStart(string='', chars=whitespace)
的第二个参数不是“针”,而是一组要修剪的字符。
_.trimStart('eq eq eq aze', 'eq ')
将返回 'az'
而不是 'aze'
。
将其视为与仅使用字符集通过正则表达式进行分割相同的方式。