怎么从字符串中取出特定符号之间的字符?如abc[123]def中的”123“该怎么取出
如何从字符串中取出特定符号之间的字符?如abc[123]def中的”123“该如何取出?
我想对字符串进行操作,目的是取出特定符号内的字符,列如字符串
dim str as string="abc[123]def"
如何取出符号"[ ]"中的123呢?
再复杂一点,str="abc[123]def[456]ghj"
如何取出“123”和“456”并分别赋值给另外两个字符串变量呢?
------解决方案--------------------
搜索"正则"
------解决方案--------------------
Dim str As String = "abc[123]def"
Dim result() As string = Regex.Matches(str, "(?<=\[)\w+(?=\])").Cast(OfType Match)().Select(Function (x) x.Value).ToArray()
------解决方案--------------------
正则: @"(?<=\[)[^\[\]]+?(?=\])"
我想对字符串进行操作,目的是取出特定符号内的字符,列如字符串
dim str as string="abc[123]def"
如何取出符号"[ ]"中的123呢?
再复杂一点,str="abc[123]def[456]ghj"
如何取出“123”和“456”并分别赋值给另外两个字符串变量呢?
字符串
字符串操作
字符串筛选
------解决方案--------------------
搜索"正则"
------解决方案--------------------
Dim str As String = "abc[123]def"
Dim result() As string = Regex.Matches(str, "(?<=\[)\w+(?=\])").Cast(OfType Match)().Select(Function (x) x.Value).ToArray()
------解决方案--------------------
正则: @"(?<=\[)[^\[\]]+?(?=\])"