以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  如何从字符串中提取时间  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=169723)

--  作者:飞云
--  发布时间:2021/6/28 11:03:00
--  如何从字符串中提取时间
字符串1:30日18:00-7月1日20:00
字符串2: 19:00至20:00
“时间”列根据情况不同内容有以上两种
请问如何得到时间1. 18:00   或  2. 19:00

--  作者:有点蓝
--  发布时间:2021/6/28 11:11:00
--  
Dim pattern As String = "([0-9]{2}):([0-9]{2})"
Dim txt = "30日18:00-7月1日20:00"
Dim rgx = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)

For Each  match As System.Text.RegularExpressions.Match In rgx.Matches(txt)
    Output.Show(match.Value )
Next

--  作者:飞云
--  发布时间:2021/6/28 12:13:00
--  
如果只想要第一个时间,比如18:00-20:00,只要18:00
--  作者:飞云
--  发布时间:2021/6/28 12:15:00
--  
知道了,我用集合方式可以吗
--  作者:有点蓝
--  发布时间:2021/6/28 13:31:00
--  
可以

msgbox(rgx.Matches(txt)(0).value)