如何让这些文件尽可能优雅?
我有一些以下形式的文件:
blur.static.shadereffect
blur.dynamic.shadereffect
blur.virtual.shadereffect
soften.static.shadereffect
soften.dynamic.shadereffect
soften.virtual.shadereffect
median.static.shadereffect
median.dynamic.shadereffect
median.virtual.shadereffect
...
现在我正在获取 .static.shadereffect
文件,然后过滤掉最后 2 部分,因此只有名称存在,例如 "blur"、"soften "、"median"
等。
某些着色器效果可以有更多或更少的类型,因此我不想硬编码 .static.shadereffect
。
因此,最终该方法将返回 .shadereffect
文件的名称:
{"blur", "soften", "median"}
如何使用尽可能少的代码最优雅地完成此操作?性能并不重要。
编辑:一个小细节。文件名也可以有超过 2 个点,例如“blur.sharpen.dynamic.shadereffect”,这不会影响结果。
I have some files in the form of:
blur.static.shadereffect
blur.dynamic.shadereffect
blur.virtual.shadereffect
soften.static.shadereffect
soften.dynamic.shadereffect
soften.virtual.shadereffect
median.static.shadereffect
median.dynamic.shadereffect
median.virtual.shadereffect
...
Right now I am getting the .static.shadereffect
files and then filtering out the last 2 parts so only the name exists like "blur", "soften", "median"
, etc.
Some shader effects can have more or less types so I don't want to hard code .static.shadereffect
.
So in the end the method will return the names of the .shadereffect
files:
{"blur", "soften", "median"}
How do I do this most elegantly with as little code as possible? Performance is not important.
EDIT: A small detail. The file names can also have more than 2 dots, so something like "blur.sharpen.dynamic.shadereffect", which shouldn't throw off the results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只会对每个文件名使用 string.Split ,然后使用 Distinct :
尽管如此,我必须承认,这可能不是最有效的方法。如果你的名字很长并且有很多点,这会浪费一些内存和时间。更好的方法是显式获取字符串到第一个点的部分:
I would just use
string.Split
for each filename, and thenDistinct
:Although, I must admit, this may not be the most efficient way. If you have long names with many dots, this will waste some memory and time. A better way would be to explicitly take the portion of the string up to the first dot:
我没有测试它,所以某处可能存在一些相差一的错误。但这应该选择除每个字符串的最后两个部分之外的所有内容。
I didn't test it, so there might be some off-by-one bug somewhere. But this should select everything except the last two parts of each string.