【发布时间】:2017-02-14 23:19:53
【问题描述】:
我正在开发一个程序,您可以在其中输入一个句子,然后搜索一个单词。然后程序会告诉你这个词出现在哪些位置。我已经写了一些代码,但不知道如何继续。
Module Module1
Sub Main()
Dim Sentence As String
Dim SentenceLength As Integer
Dim L As Integer = 0
Dim LotsofText As String = Console.ReadLine
Console.WriteLine("Enter your word ") : Sentence = Console.ReadLine
For L = 1 To LotsofText.Length
If (Mid(LotsofText, L, 1)) = " " Then
End If
L = L + 1
Dim TextCounter As Integer = 0
Dim MainWord As String = Sentence
Dim CountChar As String = " "
Do While InStr(MainWord, CountChar) > 0
MainWord = Mid(MainWord, 1 + InStr(MainWord, CountChar), Len(MainWord))
TextCounter = TextCounter + 1
'Text = TextCounter + 2
' Console.WriteLine(Text)
Loop
Console.WriteLine(TextCounter)
Console.Write("Press Enter to Exit")
Console.ReadLine()
End Sub
End Module
【问题讨论】:
-
Mid、Instr 等的存在只是为了与 VB6 和 VBA 兼容。永远不要使用它们。
标签: vb.net visual-studio vb.net-2010