I have a vb.net project on Soundex. For those who don't know, Soundex takes your inputted word and exports it to a letter and numbers.
For example:
Word: Carrot
Output: C663
I'm tasked with removing the second digit if they're directly next to each other and are the same number. So for this example, C663 would just need to output as C63. I can't seem to figure it out. I was attempting to use the Distinct clause but I just can't figure it out.
Here's my code, any help would be greatly appreciated.
Public Class Form1
Dim Word As String
Private Sub btnEncode_Click(sender As Object, e As EventArgs) Handles btnEncode.Click
Word = txtInput.Text
txtOutput.Text = Output(Word)
End Sub
Public Function Output(Word As String) As String
Return Output(Word, 4)
End Function
Public Function Output(Word As String, Length As Integer) As String
Dim returnValue As String = ""
Dim Size As Integer = Word.Length
If (Size > 1) Then
Word = Word.ToUpper()
Dim Chars() As Char = Word.ToCharArray()
Dim i As Integer
Dim wordSize As Integer = Size - 1
Dim value As Integer
Dim newString As New System.Text.StringBuilder
newString.Append(Chars(0))
For i = 1 To wordSize
Select Case Chars(i)
Case "A", "E", "I", "O", "U", "H", "W", "Y"
value = 0
Case "B", "F", "P", "V"
value = 1
Case "C", "G", "J", "K", "Q", "S", "X", "Z"
value = 2
Case "D", "T"
value = 3
Case "L"
value = 4
Case "M", "N"
value = 5
Case "R"
value = 6
End Select
If value <> 0 Then
newString.Append(value)
End If
Next
End If
Return returnValue
End Function
End Class