Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Visual Basic不使用替换或删除,仅使用长度、子字符串和索引_Vb.net_String_Replace_Indexof - Fatal编程技术网

Vb.net Visual Basic不使用替换或删除,仅使用长度、子字符串和索引

Vb.net Visual Basic不使用替换或删除,仅使用长度、子字符串和索引,vb.net,string,replace,indexof,Vb.net,String,Replace,Indexof,试图编写一个程序,在没有替换或删除方法的情况下替换和删除某些单词。仅使用诸如:Length、Substring、IndexOf之类的函数 示例:我输入“我喜欢Fives自行车店的自行车” 输出结果是:我喜欢5B的自行车 代码如下: S = txtIn.Text 'Put a space S = " " & S output = "" Acro = "" Dim L As Integer L = S.Length Dim P As Integer Dim ending, beginning

试图编写一个程序,在没有替换或删除方法的情况下替换和删除某些单词。仅使用诸如:Length、Substring、IndexOf之类的函数

示例:我输入“我喜欢Fives自行车店的自行车”

输出结果是:我喜欢5B的自行车

代码如下:

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。如果你的标签准确,你会得到更好的帮助;仅使用预定义字符串方法替换是那些预定义方法之一;怎么了?谢谢你@Sehnsucht!它只适用于一个首字母缩略词-我正在尝试在按钮中使用for循环,使其转到>1。。。e、 a如果我输入五辆自行车商店,五辆自行车商店,它将输出5BS,5BS私有子btconvert_Clicksender作为对象,e作为事件args处理btconvert。单击Dim input,Output,old,更新为字符串Dim P As Integer Dim L As Integer input=CStrtxtIn.Text L=input.Length old=Five Bike Shop NEVER=5BS For P=1 To L-1 Output=MyReplaceinput,old,newer txtOut.Text=Output NEXT什么?请把同样的话说清楚好吗?如果你想说的是,它只替换了一个事件;然后,除非我犯了错误,否则行为与字符串相同。替换它只是缺少参数验证
Function MyReplace(input As String, oldValue As String, newValue As String) As String
    Dim index = 0
    Dim output = ""
    Dim searchIndex = input.IndexOf(oldValue)

    Do Until searchIndex = -1
        output &= input.SubString(index, searchIndex - index) & newValue
        index = searchIndex + oldValue.Length
        searchIndex = input.IndexOf(oldValue, index)
    Loop

    Return output & input.Substring(index)
End Function