要求:解析字符串并取值
Dim str AsString = "[11k中国f334][22dfsk文字f3][3333][44ffffff]"
① 确认字符串的格式为四个连续的"[]"组成
② 格式正确的话,取"[]"中间的值
Imports System.Text.RegularExpressions ''' ''' 取以某字符开始,以某字符结束的字符串(正则表达式:VB.net) ''' ''' Module Module1 Sub Main() 'String to Check Dim str As String = "[11k中国f334][22dfsk文字f3][3333][44ffffff]" 'Check Format Dim mcFormatCheck As MatchCollection = Regex.Matches(str, "((\[)([^\[\]]+)(\])){4}") 'if Match If mcFormatCheck.Count = 1 Then 'Get the content between [ and ] Dim mc As MatchCollection = Regex.Matches(str, "((\[)(.+?)(\]))") For i As Integer = 0 To mc.Count - 1 'Output the items whick is matched Console.WriteLine(i.ToString() + ": " + mc.Item(i).Value) Next End If Dim c As String = Console.ReadLine() End Sub End Module
Dim str AsString = "[11k中国f334][22dfsk文字f3][3333][44ffffff]"
① 确认字符串的格式为四个连续的"[]"组成
② 格式正确的话,取"[]"中间的值
Imports System.Text.RegularExpressions ''' ''' 取以某字符开始,以某字符结束的字符串(正则表达式:VB.net) ''' ''' Module Module1 Sub Main() 'String to Check Dim str As String = "[11k中国f334][22dfsk文字f3][3333][44ffffff]" 'Check Format Dim mcFormatCheck As MatchCollection = Regex.Matches(str, "((\[)([^\[\]]+)(\])){4}") 'if Match If mcFormatCheck.Count = 1 Then 'Get the content between [ and ] Dim mc As MatchCollection = Regex.Matches(str, "((\[)(.+?)(\]))") For i As Integer = 0 To mc.Count - 1 'Output the items whick is matched Console.WriteLine(i.ToString() + ": " + mc.Item(i).Value) Next End If Dim c As String = Console.ReadLine() End Sub End Module
解析复杂字符串并提取关键信息
本文详细介绍了如何解析特定格式的字符串,并提取其中的关键信息。通过使用VB.net的正则表达式,实现对字符串中特定模式的匹配与提取。
8333

被折叠的 条评论
为什么被折叠?



