我正在編寫一個腳本來緩解字幕(srt)的生成。 我有一個熱鍵來抓取玩家的時間戳並粘貼。 然而,玩家(快速抄寫員)不幸地以這種格式顯示時間戳:00:00:00.00和SRT使用00:00:00,00。AutoHotKey正則表達式
我想做兩件事。
- 更改'。'到','
- 將時間戳存儲爲一個var,然後稍微增加最後一個毫秒。即。 00:00:00,00變成00:00:00,50
任何幫助,這將不勝感激。
我正在編寫一個腳本來緩解字幕(srt)的生成。 我有一個熱鍵來抓取玩家的時間戳並粘貼。 然而,玩家(快速抄寫員)不幸地以這種格式顯示時間戳:00:00:00.00和SRT使用00:00:00,00。AutoHotKey正則表達式
我想做兩件事。
任何幫助,這將不勝感激。
關於這個真正棘手的事情是,像
時間戳 05:59:59.60
不能輕易通過50
遞增的結果應該是
06:00:00,10
因爲百分之一秒不能超過99和第二不能超過59(就像一分鐘不能)。
所以我們需要在這裏使用了一些惱人的數學:
playerFormat := "01:10:50.70"
;extract hour, minute, second and centisecond using regex
RegExMatch(playerFormat,"O)(?P<hour>\d+):(?P<minute>\d+):(?P<second>\d+)\.(?P<centisecond>\d+)",matches)
;convert the strings to numbers by removing the leading zeros
hour := LTrim(matches.hour,"0")
minute := LTrim(matches.minute,"0")
second := LTrim(matches.second,"0")
centisecond := LTrim(matches.centisecond,"0")
;translate the total time into centiseconds
centiSecondsTotal := centisecond + second*100 + minute*100*60 + hour*100*60*60
;add 50 centiseconds (=0.5 seconds) to it
centiSecondsTotal += 50
;useing some math to translate the centisecond number that we just added the 50 to into hours, minutes, seconds and remaining centiseconds again
hour := Floor(centiSecondsTotal/(60*60*100))
centiSecondsTotal -= hour*60*60*100
minute := Floor(centiSecondsTotal/(60*100))
centiSecondsTotal -= minute*100*60
second := Floor(centiSecondsTotal/(100))
centiSecondsTotal -= second*100
centisecond := centiSecondsTotal
;add leading zeros for all numbers that only have 1 now
hour := StrLen(hour)=1 ? "0" hour : hour
minute := StrLen(minute)=1 ? "0" minute : minute
second := StrLen(second)=1 ? "0" second : second
centisecond := StrLen(centisecond)=1 ? "0" centisecond : centisecond
;create the new timestamp string
newFormat := hour ":" minute ":" second "," centisecond
MsgBox, %newFormat% ;Output is 01:10:51,20
你想做的增量正則表達式或編程語言?你試過什麼了? – Fischermaen
這是一個AutoHotKey腳本... 正則表達式專門用於檢測時間戳格式並增加它。 AHK實際上有時間格式 - 所以我可能完全跳過正則表達式。 – Funktion
落得這樣做的: 'StringReplace,中newstr,字符串,:,All' 'StringSplit,TimeArray,中newstr 「:」' 其中string是原時間(00:00:00.5) 然後拆分它,我可以添加到TimeArray – Funktion