0

I was practicing to code anagram, but I find it easy since there is this method called Array.Sort().

Without using the method above, how do you sort them alphabetically? I just switched from Java to VB.net and still learning so yea :)

Assume this is the code:

Module Module1
Sub Main()
    Dim str1, str2, str3 As String
    Dim char1(), char2(), char3() As Char

    Console.WriteLine("Enter 1st string:")
    str1 = Console.ReadLine().ToLower.Replace(" ", "")
    Console.WriteLine("Enter 1st string:")
    str2 = Console.ReadLine().ToLower.Replace(" ", "")
    Console.WriteLine("Enter 1st string:")
    str3 = Console.ReadLine().ToLower.Replace(" ", "")

    char1 = str1.ToCharArray()
    char2 = str2.ToCharArray()
    char3 = str3.ToCharArray()
End Sub End Module
Juju
  • 59
  • 1
  • 1
  • 8
  • Are you asking how to code a sort algorithm in VB.NET, instead of using one of the built in sorting methods? If so, which algorithm, and what have you tried so far? – Mark Jul 07 '15 at 16:11
  • I've tried doing a nested for loop for every character in char1 and char2, then see if they if char2(i) has values of char1(x). It's pretty complicated to be honest even I is getting confused on my codes :P – Juju Jul 07 '15 at 16:33

1 Answers1

0

If you can use Linq, you can call the OrderBy() extension on an array. Here's some examples in C#.

sort string array using LINQ

'orderby' in linq using a string array c#

You might do something like this:

Dim ordered As Char() = char1.OrderBy(Function(x) x).ToArray()
Community
  • 1
  • 1
InbetweenWeekends
  • 1,405
  • 3
  • 23
  • 28