Fatir Rizky
Fatir Rizky

Reputation: 67

Short ascending textbox number lines array order

I have Textbox Lines:

For example:

Lines1: 41,27,44,54
Lines2: 51,41,44,54
Lines3: 71,27,44,54

It should display:

Expected Output:

27,41,44,54
41,44,51,54
27,44,54,71

This is a code that doesn't work with "," it practically doesn't show me the values ​​displayed by the comma. basically shows me: 27414454 and so on...

Dim b = String.Join(",", str.Split(",").Select(Function(x) Integer.Parse(x.Trim())).OrderBy(Function(x) x))

this is a code that arranges only the lines.

        Dim textLines As List(Of String) = New List(Of String)
        textLines = TextBox2.Lines.ToList()
        textLines.Sort()

Upvotes: 2

Views: 85

Answers (1)

dr.null
dr.null

Reputation: 4660

You need to split each line to get arrays to sort, then join the arrays back to get the lines.

Here's a one liner example:

txtOutput.Lines = txtInput.Lines.
    Select(Function(x) x.Split({","c}, StringSplitOptions.RemoveEmptyEntries).
    OrderBy(Function(y) Integer.Parse(y))).
    Select(Function(z) String.Join(",", z)).ToArray

The txtInput contains:

41,27,44,54
51,41,44,54
71,27,44,54

The txtOutput displays:

27,41,44,54
41,44,51,54
27,44,54,71

Upvotes: 1

Related Questions