Vb.net 在最小长度为5、最大长度为7且包含2个点的其他两个字符串之间查找字符串
好吧,这听起来可能有点复杂,但相信我,不应该这样 我需要做的是找到一个可以是任何值的字符串,并将其放置在Vb.net 在最小长度为5、最大长度为7且包含2个点的其他两个字符串之间查找字符串,vb.net,string,Vb.net,String,好吧,这听起来可能有点复杂,但相信我,不应该这样 我需要做的是找到一个可以是任何值的字符串,并将其放置在“>”和“和”之间,类似这样的内容 Imports System.Text.RegularExpressions Module Module1 Sub Main() Console.WriteLine(FindString("<h2>5.0.77</h2>")) Console.WriteLine(FindString("&l
“>”
和“
和”之间,类似这样的内容
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Console.WriteLine(FindString("<h2>5.0.77</h2>"))
Console.WriteLine(FindString("<h2>5.77</h2>"))
Console.WriteLine(FindString("<h1>title</h1>"))
Console.WriteLine(FindString("<h2>1575.0.77</h2>"))
Console.WriteLine(FindString("<h2>2.0.77</h2>"))
Console.WriteLine(FindString("5.0.77</h2>"))
Console.ReadLine()
End Sub
Private Function FindString(ByVal Text As String) As String
Dim result As String = ""
Dim match As Match = Regex.Match(Text, ">([0-9]*\.[0-9]*\.[0-9]*)<")
If match.Groups.Count = 2 Then
If match.Groups(1).Value.Length >= 5 AndAlso match.Groups(1).Value.Length <= 7 Then
result = match.Groups(1).Value
End If
End If
Return result
End Function
End Module
导入System.Text.RegularExpressions
模块1
副标题()
Console.WriteLine(FindString(“5.0.77”))
控制台写入线(FindString(“5.77”))
Console.WriteLine(FindString(“标题”))
Console.WriteLine(FindString(“1575.0.77”))
Console.WriteLine(FindString(“2.0.77”))
Console.WriteLine(FindString(“5.0.77”))
Console.ReadLine()
端接头
私有函数FindString(ByVal文本作为字符串)作为字符串
将结果变暗为字符串=“”
Dim match As match=Regex.match(Text,“>([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)这应该有一个家庭作业标记吗?你不认为老师有足够的智慧来问这样的问题;-)为什么随机标记--你是在尝试生成这样的字符串,还是找到它们?还有一件事--。
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Console.WriteLine(FindString("<h2>5.0.77</h2>"))
Console.WriteLine(FindString("<h2>5.77</h2>"))
Console.WriteLine(FindString("<h1>title</h1>"))
Console.WriteLine(FindString("<h2>1575.0.77</h2>"))
Console.WriteLine(FindString("<h2>2.0.77</h2>"))
Console.WriteLine(FindString("5.0.77</h2>"))
Console.ReadLine()
End Sub
Private Function FindString(ByVal Text As String) As String
Dim result As String = ""
Dim match As Match = Regex.Match(Text, ">([0-9]*\.[0-9]*\.[0-9]*)<")
If match.Groups.Count = 2 Then
If match.Groups(1).Value.Length >= 5 AndAlso match.Groups(1).Value.Length <= 7 Then
result = match.Groups(1).Value
End If
End If
Return result
End Function
End Module