【发布时间】:2015-11-19 23:37:50
【问题描述】:
试图编写一个程序来替换和删除某些单词,而不使用替换或删除方法。仅使用以下函数:Length、Substring、IndexOf。
示例:我输入“我喜欢 Fives Bike Shop 的自行车”。
输出将是:“我喜欢 5BS 的自行车。”
代码如下:
S = txtIn.Text
'Put a space
S = " " & S
output = ""
Acro = ""
Dim L As Integer
L = S.Length
Dim P As Integer
Dim ending, beginning As Integer
For P = 1 To L - 1
If Acro.Length >= 25 Then
ending = S.IndexOf("Five Bike Shop", beginning)
beginning = S.IndexOf("s", beginning) + 1
Acro = S.Substring(ending)
output = output & S.Substring(ending) & "5BS"
End If
Next
txtOut.Text = output
End Sub
End Class
【问题讨论】:
-
Indexof 不是 vba 函数。你是说vb.net吗? vbavb.net。如果您的标签准确无误,您将获得更好的帮助。
-
我不明白; “仅使用预定义的字符串方法” Replace 是那些预定义的方法之一;它有什么问题?
标签: vb.net string replace indexof