Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 64 / 68

Testing whether two words are anagrams

This lesson covers testing for anagrams in VB.NET, with the aim of understanding how to sort and compare strings.

An anagram is a word made by rearranging the letters of another. Sorting the letters of each string and comparing settles whether they use the same combination.

The sample code converts each string to an array of characters with ToCharArray(), orders them with Array.Sort(), and compares with New String(charsA) = New String(charsB). "listen" and "silent" have the same letters, so sorted they match.

A common early stumble is not allowing for case. The sample unifies case with ToLower() before comparing; forget that and the same word in different cases is judged different.

Anagram testing rarely comes up directly, but combining a sort with a comparison underpins more practical work such as duplicate checking and similarity scoring.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)