我正在尝试从字符串中提取单词,然后用破折号替换偶数字符。(不包括空格)为文字游戏提供一种提示。例如:
InputString="英语语言"
输出字符串 = "#n#l#s# #a#g#a#e"
目前,我在下面使用此代码:
Private Sub Hint()
Dim InputString as string = "English Language"
dim SubInput as string()
SubInput=InputString.Split(" ")
For i=0 to UBound(SubInput) 'run through all items in SubInput array
For k=0 to SubInput(i).length-1 'run through all characters in one item
If k mod 2= 0 then 'Do the replacement if even characters found
SubInput(i)=SubInput(i).Replace(SubInput(i).Chars(k),"#")
End If
Next
Next
Dim OutputString=String.Join(" ",subInput(i))
Msgbox(OutputString)
End Sub
但是,我得到了显示这个的消息框“
#n#l#s# #a###a#e
" 单词:Language在字符号 (3) 处被错误替换
你能指出如何修复它吗?
非常感谢~