我是编程新手。我在学校学习视觉基础知识。
是否可以删除vb basic中某个字符后的所有内容?
我想做的是:以粗体字母删除所有内容
文字
background-image: url("url =** example.com %2A%7Ehmac%3D0da31302030394a84ae567e54f5cce15b3e18133&_nc_hash=AQCFmBtOnL2EgdP6**
在我的程序中,我让我的用户在文本框中输入一行文本,该行类似于文本。我无法想到如何删除 某个角色之后不必要的部分。
这是我的代码,我有2个文本框,用户将文本放在textbox1中,结果将在textbox2中。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
"i need code here"
End Sub
答案 0 :(得分:0)
您可以使用substing(从一个字符串中拆分一个字符串)和函数索引(获取给定字符的索引/位置)。 您的代码应该如下所示:
Module Module1
Sub Main()
Use this string literal for the demonstration.
Dim literal As String = "CatDogFence"
Dim pos as Integer
' Gives you the position of the D ( from DOG )
' - 1 because we dont want to see the D of dog
pos = literal.IndexOf("D") -1
' Take the first three characters into a new string.
' ... Use the Substring method.
Dim substring As String = literal.Substring(0, pos )
' substring will contain Cat , because we get from the substring
'everything from position 0 ( the start ) to 3 ( the D of Dog )
' Write the results to the screen.
Console.WriteLine("Substring: {0}", substring)
End Sub
结束模块