Programming: Anagram with the letters of a word
Solved
elmastero
Posted messages
2
Status
Member
-
elmastero Posted messages 2 Status Member -
elmastero Posted messages 2 Status Member -
Hello, I have a small programming problem in VB.NET... I’m trying to create an anagram using the letters of a word...
It’s a bit hard to describe but I hope you’ll understand :D
It’s a bit hard to describe but I hope you’ll understand :D
2 answers
-
Good evening, here’s what I found. I didn’t add comments, I hope you’ll understand ^^
Option Strict On
Option Explicit On
Module Module1
Sub Main()
Console.WriteLine("Enter a word")
Dim nombre As String
nombre = Console.ReadLine()
Dim vNom As String
Console.WriteLine("Enter a word")
Dim nombre2 As String
nombre2 = Console.ReadLine()
If FEstMemelettre(nombre, nombre2) = True Then
Console.WriteLine("annagram !!!!")
Else
Console.WriteLine("not annagram !!!!")
End If
Console.ReadLine()
'if user writes exit display array
Console.WriteLine("Type Exit to exit or enter another first name")
vNom = Console.ReadLine()
If vNom <> "exit" Then
Main()
End If
End Sub
Function FEstMemelettre(chaine1 As String, chaine2 As String) As Boolean
Dim Aretourner As Boolean
Dim longeurMots As Integer = 0
If chaine1 = chaine2 Then
Return False
End If
Dim val1 As Integer
Dim val2 As Integer
Dim tempval2 As Integer
Dim tempval As Integer
For i = 1 To Len(chaine1)
val1 = Asc(UCase(Mid(chaine1, i, 1))) - 64
tempval = val1 + tempval
val2 = Asc(UCase(Mid(chaine2, i, 1))) - 64
tempval2 = val2 + tempval2
Next
If tempval = tempval2 Then
For i2 = 1 To Len(chaine1)
For i3 = 1 To Len(chaine2)
If Mid(chaine1, i3, 1) = Mid(chaine2, i2, 1) Then
longeurMots = longeurMots + 1
If longeurMots = Len(chaine1) And longeurMots = Len(chaine2) Then
Return True
Else
Aretourner = False
End If
Else
Aretourner = False
End If
Next
Next
End If
Aretourner = False
Return Aretourner
End Function
End Module -
I tried quickly and that's what I was looking for! Thank you very much, but I haven't yet dissected the code, but thank you Yel00wStar!