Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.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中将某些字符环绕在标记周围_.net_Vb.net - Fatal编程技术网

在vb.net中将某些字符环绕在标记周围

在vb.net中将某些字符环绕在标记周围,.net,vb.net,.net,Vb.net,我正在返回一个字符串,其中包含“1.~~~~2.~~~~~3.~~~” 使用regex,我可以找到所有数字,然后使用以下句号: ([0-9]\.) 我试图用一个数字来查找所有这些事件,然后在开头加上点,并用“”和“”来包装它们 因此将包含“1.~~2.~~~~3.~~~~~” 到目前为止,我所做的一切都不起作用 Dim getLiteratura As String = "1. some text <br /> 2. some text <br /&g

我正在返回一个字符串,其中包含“1.~~~~2.~~~~~3.~~~”

使用regex,我可以找到所有数字,然后使用以下句号:

([0-9]\.)
我试图用一个数字来查找所有这些事件,然后在开头加上点,并用“
”和“
”来包装它们

因此将包含“
1.

~~2.

~~~~3.~~~~~

到目前为止,我所做的一切都不起作用

            Dim getLiteratura As String = "1. some text <br /> 2. some text <br /> 3. some text"
            Dim Pattern As String = "/^[0-9]\./gm"
            Dim ReturnedMatches As MatchCollection = Regex.Matches(getLiteratura, Pattern)
            For Each ReturnedMatch As Match In ReturnedMatches
              //here for each occurance wrap p tags around match
               dim sss as string = sss & "<p>" & ReturnedMatch & "</p>"
            Next
Dim getLiteratura As String=“1.一些文本
2.一些文本
3.一些文本” Dim模式为String=“/^[0-9]\./gm” Dim ReturnedMatches As MatchCollection=Regex.Matches(getLiteratura,Pattern) 对于每个ReturnedMatch作为ReturnedMatch中的匹配项 //在这里,对于每种情况,在匹配的周围环绕p标记 将sss作为字符串设置为dim=sss&“”&ReturnedMatch&“

” 下一个
以上这些似乎不起作用,我也不知道为什么


谢谢

我对正则表达式不是很满意,但可以用老式的方法来做

    Dim getLiteratura As String = "1. some text <br /> 2. some text <br /> 3. some text"
    'changing the name of your variable to save space
    Dim s As String = getLiteratura
    Dim newStringBuilder As New StringBuilder
    For index As Integer = 0 To s.Length - 1
        If index = s.Length - 1 Then
            newStringBuilder.Append(s(index))
            Continue For
        End If
        If Char.IsNumber(s(index)) And s(index + 1) = "." Then
            newStringBuilder.Append("<p>" & s(index))
        ElseIf s(index) = "." And Char.IsNumber(s(index - 1)) Then
            newStringBuilder.Append(".</p>)")
        Else
            newStringBuilder.Append(s(index))
        End If
    Next
    Dim newString = newStringBuilder.ToString()
    Debug.Print(newString)
    'Output
    '<p>1.</p>) some text <br /> <p>2.</p>) some text <br /> <p>3.</p>) some text
Dim getLiteratura As String=“1.一些文本
2.一些文本
3.一些文本” '更改变量名称以节省空间 Dim s As String=Get Dim newStringBuilder作为新的StringBuilder 对于作为整数的索引=0到s。长度-1 如果索引=s.长度-1,则 newStringBuilder.Append(s(索引)) 继续 如果结束 如果Char.IsNumber(s(index))和s(index+1)=“则 newStringBuilder.Append(“”&s(索引)) ElseIf s(index)=“.”和Char.IsNumber(s(index-1)),然后 newStringBuilder.Append(“.

)”) 其他的 newStringBuilder.Append(s(索引)) 如果结束 下一个 Dim newString=newStringBuilder.ToString() Debug.Print(新闻字符串) "产出", “1.

)一些文本
2.

)一些文本
3.

)一些文本
好的,您面临什么问题?你没有告诉我们怎么了,也没有问我们问题。意向声明不构成问题。道歉,描述修改谢谢。所以…“不起作用”确切地说是什么意思?你有错误吗?或者结果不是你所期望的?请让我们知道您的代码当前输出的内容。此外,如果示例代码使用了与上面给出的示例相同的输入数据,则更容易理解。然后,我们可以期望在这两种情况下都有相同的输出。如果我响应,它不会返回任何内容。编写字符串,它不会打印任何内容。顺便问一下,您是否注意到问题文本中的正则表达式与代码中的正则表达式不同。