如何为数字的字符串作为Numerics的梳理? [英] How to sort out numeric strings as numerics?
问题描述
如果你有这样的字符串:
If you have strings like:
"file_0"
"file_1"
"file_2"
"file_3"
"file_4"
"file_5"
"file_6"
"file_11"
您
如何才能对它们进行排序,使file_11不来file_1之后,却来后file_6,自11> 6。
how can you sort them so that "file_11" doesn't come after "file_1", but comes after "file_6", since 11 > 6.
我必须分析字符串,并将其转换成一个数字呢?
Do I have to parse the string and convert it into a number for this?
Windows资源管理器在Win7排序文件出来我想要的方式。
Windows explorer in Win7 sorts files out the way I wanted.
推荐答案
您可以导入 StrCmpLogicalW功能< /一>,并用它来对字符串进行排序。这是非常相同的函数,资源管理器本身使用的文件名。
You could import the StrCmpLogicalW function and use that to sort the strings. This is the very same function that Explorer itself uses for file names.
不会帮助你,如果你不希望的P / Invoke或留在其他系统兼容,但。
Won't help you if you don't want P/Invoke or stay compatible on other systems, though.
这篇关于如何为数字的字符串作为Numerics的梳理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!