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
2
  • 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? Commented Jul 7, 2015 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 Commented Jul 7, 2015 at 16:33

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.