我在找一些说明。我有一个组合框,它由SQL数据库中的两个表连接填充。文本示例:“野生-2014年11月16日凌晨2:00”。我试图让staA举行“野生”和staB "11/16/2014凌晨2:00“。长度。我尝试在“-”上使用传统的字符串拆分,但这只返回第一个单词。接下来,我尝试了regex语句:
Dim input As String = strA
Dim pattern As String = "-"
Dim substring() As String = Regex.Split(input, pattern)
For Each match As String In substring
Console.WriteLine("'{0}'", match)
Next但不确定如何验证是否发生了拆分,也不确定如何从拆分中访问信息。
发布于 2014-12-10 02:46:19
我更喜欢用regex使用组来做这样的事情。
通过这种方式,您可以检测到没有预期的模式来处理其他输入。
pattern = "^(?<a>[^-]+) - (?<b>[^-]+)$"
dim m as match=regex.match(input,pattern)
dim a as string=""
dim b as string=""
if m.success then
a=m.groups("a").value
b=m.groups("b").value
end ifhttps://stackoverflow.com/questions/27392427
复制相似问题