How to sort the digits of a number in descending order with VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq
				
Public Module Module1
	Public Sub Main()
		Dim n As Integer = 81925

        Try
            Dim s As String = n.ToString()
            s = String.Concat(s.OrderByDescending(Function(ch) ch))
            n = Int32.Parse(s)
            Console.WriteLine(n)
        Catch e As FormatException
            Console.WriteLine(e.Message)
        End Try
	End Sub
End Module




' run:
' 
' 
' 98521
'

 



answered Mar 27, 2021 by avibootz

Related questions

2 answers 274 views
1 answer 156 views
2 answers 200 views
...