如何在 Vbscript 中将时间码字符串更改为数字?

How do I change timecode strings into numerals in Vbscript?

我有这种形式的字符串条目:

002  0000     A     C        00:00:20:01 00:00:31:23 00:01:29:24 00:01:41:21

从上一个问题我可以捕捉到它:

Set re = New RegExp
re.Pattern = "C        (\d{2}:\d{2}:\d{2}:\d{2}) (\d{2}:\d{2}:\d{2}:\d{2})"
matches = re.Execute(prev)

现在我有 2 个子匹配项需要对其执行算术运算。

我如何将每个子匹配项分离成由“:”分隔的数字对列表(不确定术语?)?

这些字符串是我想分解为帧数的时间戳。

我希望将时间码转换为每秒 25 帧:

  1. 第一对是小时到帧时基(25fps) 1小时=1*60*(60*25)=9000
  2. 第二对是分钟到帧时基(25fps) 1分钟=1*(60*25)=1500
  3. 第三对是秒到帧时基(25fps)1秒=1*25f

例如 00:02:20:01 的子匹配将转换为 3501

上一个

编辑 这就是我最终得到的。我必须找到在 "seconds" 中返回答案的时间值之间的差异 (datediff),然后我将其转换为带有时间序列的时间格式。但它附加了一个 AM/PM 时钟,所以我将脚本区域设置为德国,这关闭了 AM/PM 后缀。

Option Explicit
'change system location to Germany, to simulate 24hour clock *no AM PM time
setlocale "de-de"

'TBA read whole data doc to grab the NameDetails and TC


    Dim TC
    'temporary data set, I will need to send each line to this search
    TC ="002  0000     A     C        00:00:20:01 00:00:23:23 00:01:29:24 00:01:41:21"

    'Define search terms for each timecode element *this is not a result yet
    Dim re1
    re1 =".*?"  'Non-greedy match on filler
    Dim re2
    re2 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"  'HourMinuteSec 1
    Dim re3
    re3 =".*?"  'Non-greedy match on filler
    Dim re4
    re4 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 2
    Dim re5
    re5 =".*?"  'Non-greedy match on filler
    Dim re6
    re6 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 3
    Dim re7
    re7 =".*?"  'Non-greedy match on filler
    Dim re8
    re8 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 4

    'add timecode search terms to a search pattern
    Dim r
    Set r = New RegExp
    r.Pattern = re1+re2+re3+re4+re5+re6+re7+re8
    r.IgnoreCase = True

    Dim m, timeDur, ts, Timeofday
    Set m = r.Execute(TC)
    'loop through timecodes to find duration between first 2 entries
    If m.Item(0).SubMatches.Count > 0 Then
        Dim time1
        time1=m.Item(0).SubMatches.Item(0)
        Dim time2
        time2=m.Item(0).SubMatches.Item(1)
        Dim time3
        time3=m.Item(0).SubMatches.Item(2)
        Dim time4
        time4=m.Item(0).SubMatches.Item(3)

        'find duration/difference between first 2 times, in seconds
        timeDur=datediff("s", time1, time2)
        'format result to a serial time format eg. 00:00:00
        ts = TimeSerial(0, 0, timeDur)
        'print duration result, will need to append track info and repeat. Then save to file
        MsgBox (ts)

    End If

所以,最终我猜你想匹配正则表达式 "time",并使用 VBScript 函数 "split"...下面是一个可能对你有帮助的例子:

Dim txt
txt ="002  0000     A     C        00:00:20:01 00:00:31:23 00:01:29:24 00:01:41:21"

Dim re1
re1 =".*?"  'Non-greedy match on filler
Dim re2
re2 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-  9])?(?:\s?(?:am|AM|pm|PM))?)"  'HourMinuteSec 1
Dim re3
re3 =".*?"  'Non-greedy match on filler
Dim re4
re4 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 2
Dim re5
re5 =".*?"  'Non-greedy match on filler
Dim re6
re6 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 3
Dim re7
re7 =".*?"  'Non-greedy match on filler
Dim re8
re8 ="((?:(?:[0-1][0-9])|(?:[2][0-3])|(?:[0-9])):(?:[0-5][0-9])(?::[0-5][0-9])?(?:\s?(?:am|AM|pm|PM))?)"    'HourMinuteSec 4

Dim r
Set r = New RegExp
r.Pattern = re1+re2+re3+re4+re5+re6+re7+re8
r.IgnoreCase = True
Dim m
Set m = r.Execute(txt)
If m.Item(0).SubMatches.Count > 0 Then
    Dim time1
    time1=m.Item(0).SubMatches.Item(0)
    Dim time2
    time2=m.Item(0).SubMatches.Item(1)
    Dim time3
    time3=m.Item(0).SubMatches.Item(2)
    Dim time4
    time4=m.Item(0).SubMatches.Item(3)
    Response.Write("("+Replace(time1,"<","&lt;")+")"+"("+Replace(time2,"<","&lt;")+")"+"("+Replace(time3,"<","&lt;")+")"+"("+Replace(time4,"<","&lt;")+")"+"")
End If