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
String VB.NET获取字符串中字符的编号位置(的索引)_String_Vb.net_Indexing - Fatal编程技术网

String VB.NET获取字符串中字符的编号位置(的索引)

String VB.NET获取字符串中字符的编号位置(的索引),string,vb.net,indexing,String,Vb.net,Indexing,我很难让函数正常工作。我需要搜索message.text for each、found、for each、found我需要获取字符串中“”所在位置的编号位置。例如:23232111102020332,12它将返回“”所在的6/10/19(索引)。我的代码找到了第一个的第一个索引,但只需重复6次,任何帮助都将不胜感激 这是我的密码: For Each i As Char In message.Text If message.Text.Contains(",") Then

我很难让函数正常工作。我需要搜索message.text for each、found、for each、found我需要获取字符串中“”所在位置的编号位置。例如:23232111102020332,12它将返回“”所在的6/10/19(索引)。我的代码找到了第一个的第一个索引,但只需重复6次,任何帮助都将不胜感激

这是我的密码:

    For Each i As Char In message.Text
        If message.Text.Contains(",") Then
            Dim data As String = message.Text
            Dim index As Integer = System.Text.RegularExpressions.Regex.Match(data, ",").Index
            commas.AppendText(index & " ")
        End If
    Next

你可以这样尝试;实例化一个
Regex
对象,并在每次开始匹配的位置递增(这种可能性在静态方法
Match
中不可用)


p、 s返回的索引是基于零的,只需使用Regex.Matches方法即可

    Dim message As String = "23232,111,02020332,12"
    Dim result As String = ""

    For Each m As Match In Regex.Matches(message, ",")
        result &= m.Index + 1 & " "
    Next
我还应该补充一点,索引是基于0的(这就是为什么将+1添加到m.Index)。如果以后需要这些值来指向特定逗号的位置,则可能会禁用1,并可能尝试访问比实际字符串大的索引

    Dim message As String = "23232,111,02020332,12"
    Dim result As String = ""

    For Each m As Match In Regex.Matches(message, ",")
        result &= m.Index + 1 & " "
    Next