2016-01-13 29 views
0

我正在編寫一個腳本來緩解字幕(srt)的生成。 我有一個熱鍵來抓取玩家的時間戳並粘貼。 然而,玩家(快速抄寫員)不幸地以這種格式顯示時間戳:00:00:00.00和SRT使用00:00:00,00。AutoHotKey正則表達式

我想做兩件事。

  1. 更改'。'到','
  2. 將時間戳存儲爲一個var,然後稍微增加最後一個毫秒。即。 00:00:00,00變成00:00:00,50

任何幫助,這將不勝感激。

+1

你想做的增量正則表達式或編程語言?你試過什麼了? – Fischermaen

+0

這是一個AutoHotKey腳本... 正則表達式專門用於檢測時間戳格式並增加它。 AHK實際上有時間格式 - 所以我可能完全跳過正則表達式。 – Funktion

+0

落得這樣做的: 'StringReplace,中newstr,字符串,:,All' 'StringSplit,TimeArray,中newstr 「:」' 其中string是原時間(00:00:00.5) 然後拆分它,我可以添加到TimeArray – Funktion

回答

2

關於這個真正棘手的事情是,像
時間戳 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 
+0

太棒了。 。 在我讀這篇文章之前,我的修復只是將00加到了釐秒的末尾。然後只增加1.如果它恰好是9 - 在添加1之前將其設爲8。朋友之間的差距是多少釐米;-)但是,您的解決方案非常好,而且功能更強大。 – Funktion

+0

一釐秒是百分之一秒。意思是100釐秒= 1秒。就像100釐米就是1米。 – Forivin