0
私は、文中の単語の位置を出力するフォームのビジュアルな基本プログラムを作成しました。方法は、私は数字だけで全体の文を出力することができます:猫は1,2,3,4,1,6,7だろう別の猫と戦った。文の中の単語を特定し、リストに格納し、リスト内のその単語の位置に各単語を置き換えるプログラム
本当にありがとうございます。
私は、文中の単語の位置を出力するフォームのビジュアルな基本プログラムを作成しました。方法は、私は数字だけで全体の文を出力することができます:猫は1,2,3,4,1,6,7だろう別の猫と戦った。文の中の単語を特定し、リストに格納し、リスト内のその単語の位置に各単語を置き換えるプログラム
本当にありがとうございます。
あなたがする必要があるのは、文中の別個の単語のリストを取得し、その文の各単語を繰り返して、その単語の単語のインデックスを出力として置き換えることだけです。これを実現する方法の例を次に示します。
Dim UserInput1 As String = "The cat fought another cat would be"
Dim words As New List(Of String)
'Here, we just add get a list of the distinct words in the sentence
For Each Word As String In UserInput1.ToLower.Split(CChar(" "))
If Not words.Contains(Word) Then words.Add(Word)
Next
'Looping through the words and their indexes
'to show their relation just for this example
For i As Integer = 0 To Words.Count - 1
Debug.Print((i + 1).ToString & " = " & Words(i))
Next
'Outputs:
'1 = the
'2 = cat
'3 = fought
'4 = another
'5 = would
'6 = be
'So now that we have our number/word relations,
'we can just loop through the words and get the
'output that you wanted, an index substitution of each word
Dim output As String = Nothing
For Each Word As String In UserInput1.ToLower.Split(CChar(" "))
output &= (words.IndexOf(Word) + 1).ToString & ", "
Next
output = output.Substring(0, output.Length - 2)
'output = "1, 2, 3, 4, 2, 5, 6"