Sorting list by a certain column

Hello how would I sort a list of constant strings that I put into 1 constant string be sorted by the 11th column(The Price) image

Please provide a sample list via text, I don’t want to type everything by hand.

NV 1033   9.97    No   8
NV 1024   6.57    No   5
NV 2844   7.47    No   2
NV 1537   6.17    No   1
NV 2477   23.57   No   5
NV 1620   7.27    No   4
NV 0784   9.97    No   4
NV 1639   14.97   No   5
NV 0321   8.97    No   5
NV 1703   10.57   No   10
NV 1719   15.07   No   5
NV 2661   6.37    No   1
NV 2271   8.67    No   1
NV 1836   14.97   No   2
NV 1863   6.17    No   5
NV 2721   8.67    No   3
BLOCK:ConstantList
  value = ["NV 1033 9.97 No 8", "NV 1024 6.57 No 5", "NV 2844 7.47 No 2", "NV 1537 6.17 No 1", "NV 2477 23.57 No 5", "NV 1620 7.27 No 4", "NV 0784 9.97 No 4", "NV 1639 14.97 No 5", "NV 0321 8.97 No 5", "NV 1703 10.57 No 10", "NV 1719 15.07 No 5", "NV 2661 6.37 No 1", "NV 2271 8.67 No 1", "NV 1836 14.97 No 2", "NV 1863 6.17 No 5", "NV 2721 8.67 No 3"]
  => VAR @list
ENDBLOCK

var orderedList = list.OrderBy(i => {
  var match = System.Text.RegularExpressions.Regex.Match(i, "[A-Z]{2} [0-9]+ ([0-9\\.]+)").Groups[1].Value;
  return double.Parse(match);
}).ToList();

var reversedList = orderedList.ToList();
reversedList.Reverse();

It returned “[Executing block LoliCode] FormatException: Input string was not in a correct format.”


could this be because in every Line constant string at the end there is a \n so it goes to the next line in the discord

Why are you doing that in the constant list? That’s completely wrong. I need to know which data you’re working on otherwise I cannot help you. I need to know how you’re parsing it EXACTLY.

I put the <Line> variables because in each one there is


The prefix and prefixx strings could be a space or blank depending on how much characters are in the price that is so the entire things is all lined up so its not messy and the \\n is so it goes to the next line in discord but the problem is since I have it set up so if the price is lower than the msrp it just turns that <Line> variable that its in empty and that causes the constant list to add random ,image
which I think is causing that problem at least I think unless its just the \\n causing it

So you’re parsing every line with a different block? Man that’s not very good… You should parse recursively. Is there any reason why you’re doing that?

it was the only way I thought of doing this entire config I mean there is another config but for all stores which is like 120k lines in lollicode which is just the same part repeating 1272 times

Anyways, if you want to go with your method, you need to put the constant list with dark green background otherwise it will not replace the variables inside the list. Or simply add a $ before the first square bracket in the lolicode like this

value = $["<Line1>", ...]

I keep getting
[IDLE] CompilationErrorException: (1325,60): error CS1503: Argument 1: cannot convert from 'char' to 'string'
when I put


and this is what happens throughout that

no matter if I remove the [ and ] with the replace blocks or not it will still give me that error not sure what I am doing wrong I have the other replace blocks to fix the extra ,'s

Replace only works on strings, not lists. You don’t need to replace the comma at all. You need to pass the list directly ot the snippet above and then you can use the join block to convert it back if you want.

But if I just pass the list directly it does this image

so is there any fix to the error above?

Hi so I finally found a website Alphabetizer and they have the option to Sort at column number 11 Naturally
which sorts my list
`

NV 1033   9.97    No   8
NV 1024   6.57    No   5
NV 2844   7.47    No   2
NV 1537   6.17    No   1
NV 2477   23.57   No   5
NV 1620   7.27    No   4
NV 0784   9.97    No   4
NV 1639   14.97   No   5
NV 0321   8.97    No   5
NV 1703   10.57   No   10
NV 1719   15.07   No   5
NV 2661   6.37    No   1
NV 2271   8.67    No   1
NV 1836   14.97   No   2
NV 1863   6.17    No   5
NV 2721   8.67    No   3

TO

NV 1537   6.17    No   1
NV 1863   6.17    No   5
NV 2661   6.37    No   1
NV 1024   6.57    No   5
NV 1620   7.27    No   4
NV 2844   7.47    No   2
NV 2271   8.67    No   1
NV 2721   8.67    No   3
NV 0321   8.97    No   5
NV 0784   9.97    No   4
NV 1033   9.97    No   8
NV 1703   10.57   No   10
NV 1836   14.97   No   2
NV 1639   14.97   No   5
NV 1719   15.07   No   5
NV 2477   23.57   No   5

how would I implement this into my config? because they don’t use apis to do this

I told you how to do it, but the fact is that you need to learn the basics of OB2 first because you’re trying to sort a string with return characters instead of a list.

So when I put your exact code it works as expected even when I put different lists with different values but as soon as I changed one line from the example you sent into an empty line it gives the incorrect format error is there anyway to make it ignore empty lines?

EDIT: All I had to do was use a Remove All From List with the term box empty sorry for stretching this out because of one error

1 Like