Join Method String Manipulation Visual Basic

时间:2014-01-06 16:07:06

标签: vb.net visual-studio-2013

关于在Visual Basic(VB.Net)上使用Join Method String Manipulation处理ReDim方法,我需要一点帮助。

目标是制作一个使用输入框的程序。

输入框必须是循环,并且一次显示一个单词,直到达到限制为止,按下指定的命令。

简而言之,没有固定的循环,它将取决于用户有多少循环被覆盖。

完成后,join方法根据用户输入的数量而工作。示例:“Hello + Hi + testing + one + two + Three + four + five”

这是我的代码,直到现在我都无法理解。

    Dim inputtext As String
    Dim counter As Integer
    Dim language() As String


 Do Until inputtext = "."
        inputtext = InputBox("Enter the language as many as you can")
        MsgBox(inputtext)
        counter = counter + 1
    Loop

    ReDim Preserve language(inputtext)


    inputtext = String.Join("+", language)
    MsgBox(inputtext.ToString)

2 个答案:

答案 0 :(得分:0)

根据您的描述,我认为您需要的是如下: 请参阅我已更新 Do..Until 代码块。

 Dim inputtext As String=""
    Dim counter As Integer =0
    Dim language(0) As String


 Do Until inputtext = "."
        inputtext = InputBox("Enter the language as many as you can")
        ReDim Preserve language(UBound(language) + 1)
        language(counter) = inputtext 
        MsgBox(inputtext)
        counter = counter + 1

    Loop

   ' ReDim Preserve language(inputtext)


    inputtext = String.Join("+", language)
    MsgBox(inputtext.ToString)

答案 1 :(得分:0)

你应该重新调整数组并在循环中添加inputtext,否则你只会添加最后一个值。您还应该测试终止值,只有在不同时添加:

Dim inputtext As String
Dim counter As Integer
Dim language() As String

Do Until inputtext = "."
    inputtext = InputBox("Enter the language as many as you can")
    If inputtext <> "." Then
        MsgBox(inputtext)
        ReDim Preserve language(counter)
        language(counter) = inputtext
        counter = counter + 1
    End If
Loop

inputtext = String.Join("+", language)
MsgBox(inputtext.ToString)

Dim inputtext As String Dim counter As Integer Dim language() As String Do Until inputtext = "." inputtext = InputBox("Enter the language as many as you can") If inputtext <> "." Then MsgBox(inputtext) ReDim Preserve language(counter) language(counter) = inputtext counter = counter + 1 End If Loop inputtext = String.Join("+", language) MsgBox(inputtext.ToString)