Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.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中检测字符串中的特定字符?_Vb.net_String_Character_Detection - Fatal编程技术网

如何在VB.NET中检测字符串中的特定字符?

如何在VB.NET中检测字符串中的特定字符?,vb.net,string,character,detection,Vb.net,String,Character,Detection,好的,在我在VB.NET中开发的一个程序中,我试图创建一个字符串列表(每个字符串位于不同的行上)。对于每一行,我想把它分成三部分。第一部分从字符串的开头到字符串中的第一个冒号,第二部分从第一个冒号到at符号,最后一部分从at符号到字符串的结尾 例如,我将采用一系列行中的一行: 你好:world@yay 我想把它分成三个独立的字符串“你好”、“世界”和“耶” 在VB.NET中如何做这样的事情?您可以通过拆分来完成这一点。例如,我正在重新拆分一个本来可以保存下来的字符串,这样就不必再拆分它了。但是,

好的,在我在VB.NET中开发的一个程序中,我试图创建一个字符串列表(每个字符串位于不同的行上)。对于每一行,我想把它分成三部分。第一部分从字符串的开头到字符串中的第一个冒号,第二部分从第一个冒号到at符号,最后一部分从at符号到字符串的结尾

例如,我将采用一系列行中的一行: 你好:world@yay

我想把它分成三个独立的字符串“你好”、“世界”和“耶”


在VB.NET中如何做这样的事情?

您可以通过拆分
来完成这一点。例如,我正在重新拆分一个本来可以保存下来的字符串,这样就不必再拆分它了。但是,用这种方式理解更简单:

Dim s as String = "hello:world@yay" 'This can be a string from a loop.
Dim hello As String = s.Split(":")(0)  'Get everything before colon.
Dim world As String = s.Split(":")(1).Split("@")(0) 'Get everything after colon, and split the result again, grabbing everything before the amp.
Dim yay As String = s.Split(":")(1).Split("@")(1) 'Get everything after colon, and split the result again, grabbing everything after the amp.
如果您正在读取文本文件,例如

    Dim objReader As New StreamReader("c:\test.txt")
    Dim s As String = ""
    Dim hello As String
    Dim world As String
    Dim yay As String

    Do
        s = objReader.ReadLine()
        If Not s Is Nothing Then
           hello = s.Split(":")(0)
           world = s.Split(":")(1).Split("@")(0)
           yay = s.Split(":")(1).Split("@")(1)
        End If
    Loop Until s Is Nothing
    objReader.Close()

您可以通过拆分
来完成此操作。例如,我正在重新拆分一个本来可以保存下来的字符串,这样就不必再拆分它了。但是,用这种方式理解更简单:

Dim s as String = "hello:world@yay" 'This can be a string from a loop.
Dim hello As String = s.Split(":")(0)  'Get everything before colon.
Dim world As String = s.Split(":")(1).Split("@")(0) 'Get everything after colon, and split the result again, grabbing everything before the amp.
Dim yay As String = s.Split(":")(1).Split("@")(1) 'Get everything after colon, and split the result again, grabbing everything after the amp.
如果您正在读取文本文件,例如

    Dim objReader As New StreamReader("c:\test.txt")
    Dim s As String = ""
    Dim hello As String
    Dim world As String
    Dim yay As String

    Do
        s = objReader.ReadLine()
        If Not s Is Nothing Then
           hello = s.Split(":")(0)
           world = s.Split(":")(1).Split("@")(0)
           yay = s.Split(":")(1).Split("@")(1)
        End If
    Loop Until s Is Nothing
    objReader.Close()
使用

首先使用“:”拆分字符串,然后使用“@”拆分第二个编辑元素


首先用“:”拆分字符串,然后用“@”

拆分第二个编辑元素查看string.indexOf并从中获取它查看string.indexOf并从中获取它

好吧,我又有点卡住了,我该如何实现一个get next line方法来从列表中放入s?好吧,我又有点卡住了,我将如何实现一个get next line方法,将其放入列表中的s中?