我有两个这种形式的数组列表:
\ndef AllowedExtensions = [ '.mxf', '.mov', '.mp4']\ndef myPaths = [C:\\Temp\\Media\\Media.c2v, C:\\Temp\\Media\\Media.V2C, C:\\Temp\\Media\\toto\\test\\\xe5\xb7\xa8\xe5\xa1\x94\xe3\x81\xae\xe7\xb5\x82\xe3\x82\x8f\xe3\x82\x8a.mp4, C:\\Temp\\Media\\toto\\toto.mxf]\nRun Code Online (Sandbox Code Playgroud)\n我正在尝试构建一个新列表,mySelectedPath仅myPaths当它与 \n中的扩展名之一匹配时,我AllowedExtensions正在寻找一种常规方法来执行此操作,但无法使其正常工作。
AllowedExtensions.each { mySelectedPath = myPaths.findAll { it }}\nRun Code Online (Sandbox Code Playgroud)\n这是我的预期结果:
\n[C:\\Temp\\MediaNavigator\\toto\\toto.mxf, C:\\Temp\\MediaNavigator\\toto\\test\\\xe5\xb7\xa8\xe5\xa1\x94\xe3\x81\xae\xe7\xb5\x82\xe3\x82\x8f\xe3\x82\x8a.mp4]\nRun Code Online (Sandbox Code Playgroud)\n感谢您的任何意见!
\n另一种解决方案是使用findResults
allowedExtensions.findResults { ext -> myPaths.find { it.endsWith ext } }
Run Code Online (Sandbox Code Playgroud)
如果您希望每个扩展程序有多个结果,请尝试:
allowedExtensions.findResults { ext -> myPaths.findAll { it.endsWith ext } }.flatten()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
97 次 |
| 最近记录: |