How to sort out numeric strings as numerics?

前端 未结 6 2013
面向向阳花
面向向阳花 2020-12-30 09:04

If you have strings like:

\"file_0\"
\"file_1\"
\"file_2\"
\"file_3\"
\"file_4\"
\"file_5\"
\"file_6\"
\"file_11\"

how can you sort them so

6条回答
  •  爱一瞬间的悲伤
    2020-12-30 09:26

    A simple way is to pad the numeric portion like so:

    file_00001
    file_00002
    file_00010
    file_00011
    

    etc.

    But this reles on knowing the maximum value the numeric portion can take.

提交回复
热议问题