Archive: Sort content of file by string length


Sort content of file by string length
  Hi,

i am trying to sort a content of a file by string length, for sample:
unsorted.log


123

1
12345
12
12
1234
>
to ->
sorted.log

12345

1234
12
12
1
>
Maybe it helps if i add the strlen to the file on write
unsorted.log

123

>(1)1
>(5)12345
>(2)12
>(2)12
>(4)1234
>
Regards,

Bernhard

Read each line and write it to the registry under a key name and value name of:

WriteRegStr HKCU "Software\MyApp\[line length]" "[line #]" "[line text]"

You should be able to use EnumRegKeys and EnumRegValues to enumerate them in order.

If EnumRegKeys/EnumRegValues does not give you back the values in order then you would need to use two counters for the line lengths and line numbers instead and just use ReadRegStr on its own. You would need to keep track of the highest line length and the number of lines so that you know when to stop counting. If you choose this method you could use an INI file instead.

Note that any lines over NSIS_MAX_STRLEN (1024 by default) will be truncated therefore you could instead sort using some code written in C or something which you call in a DLL.

You could also use the NSISArray plug-in but you still hit the 1024 string length limit when you use FileRead.

Stu