在VB.Net字符串中查找brakets
我希望为虚拟钢琴制作一个解码器,它将从这里获取乐谱()并将其转换为自动热键脚本。但我遇到了一个问题,无法检测何时应该同时播放音符, 例子 如果我要输入 G ou[pT][OT] 结果应该是在VB.Net字符串中查找brakets,vb.net,Vb.net,我希望为虚拟钢琴制作一个解码器,它将从这里获取乐谱()并将其转换为自动热键脚本。但我遇到了一个问题,无法检测何时应该同时播放音符, 例子 如果我要输入 G ou[pT][OT] 结果应该是 Send G Sleep, 100 Sleep, 100 Send o Sleep, 100 Send u Sleep, 100 Sleep, 100 Send p Send T Sleep, 100 Send O Send T Sleep, 100 但结果是 Send G Sleep, 100 Sleep
Send G
Sleep, 100
Sleep, 100
Send o
Sleep, 100
Send u
Sleep, 100
Sleep, 100
Send p
Send T
Sleep, 100
Send O
Send T
Sleep, 100
但结果是
Send G
Sleep, 100
Sleep, 100
Send o
Sleep, 100
Send u
Sleep, 100
Sleep, 100
Send p
Sleep, 100
Send T
Sleep, 100
Send O
Sleep, 100
Send T
Sleep, 100
我希望找到“[”和“]”的位置,然后在两者之间更改文本
我跟她说了是的
start = TextBox1.Text
Arraycounter = 0
Do Until -1 = start.IndexOf("[")
Front = start.IndexOf("[")
Back = start.IndexOf("]")
counter = Front
Do Until counter = Back + 1
Middle = Middle & start(counter)
counter += 1
Loop
counter = 0
MsgBox(Front & " - " & Back & " - " & Middle)
start = Replace(start, Middle, SymbleArray(Arraycounter))
Middle = Replace(Middle, "[", "")
Middle = Replace(Middle, "]", "")
Do Until counter = Middle.Length
outp = outp & Replace(Middle(counter), Middle(counter), "SEND " & Middle(counter) & vbNewLine)
counter += 1
Loop
MsgBox(outp)
BraketArray(Arraycounter) = outp
Arraycounter += 1
Middle = ""
outp = ""
Loop
Arraycounter = 0
Do Until Arraycounter = 11
start = Replace(start, SymbleArray(Arraycounter), BraketArray(Arraycounter))
Arraycounter += 1
Loop
TextBox2.Text = start
End Sub
我试图简化您的代码。将此代码放入空白控制台项目中。或者,如果要使用WinForm,请将Console.WriteLine(“某些字符串”)更改为文本框,例如Textbox2.Text=“某些字符串” 我删除了]]之间的空格以匹配预期结果。我还使用Sleep,200表示空格。如果需要处理一些特殊符号,只需将它们添加到case语句中即可 守则的结果:
Send G
Sleep, 100
Sleep, 200
Send o
Sleep, 100
Send u
Sleep, 100
Sleep, 200
Send p
Send T
Sleep, 100
Send O
Send T
Sleep, 100
请告诉我,如果我需要更清楚,因为我不擅长打字,如果你想看到我的完整代码只是作为你的代码的后期。我认为你应该处理每个字符,而不是使用替换函数。好的,我已经发布了我的完整代码,我想这是缩短代码的一种方法,我只是自己写出来,但我不知道简而言之,这将是我能问的最后一件事,因为我已经有一个关于-1的问题了,那么我该如何在正常形式下使用它呢?我有点迷路了,很抱歉在winform中?从输入文本框设置输入,然后将Console.WriteLine更改为我在回答中所写的文本框。Dim input=“G ou[pT][OT]”将更改为Dim input=Textbox1.TextConsole.WriteLine(“睡眠,200”)将更改为Textbox2.Text=“睡眠,200”
Send G
Sleep, 100
Sleep, 200
Send o
Sleep, 100
Send u
Sleep, 100
Sleep, 200
Send p
Send T
Sleep, 100
Send O
Send T
Sleep, 100