00:0开发者_如何学Go0:04,000\", hour,minutes,seconds,mili seconds." />
开发者

how do I test the format of a string?

开发者 https://www.devze.com 2022-12-12 20:57 出处:网络
Im having trouble matching the format of a string, the format is that of the .srt timing which is \"00:00:01,000 --> 00:0开发者_如何学Go0:04,000\", hour,minutes,seconds,mili seconds.

Im having trouble matching the format of a string, the format is that of the .srt timing which is "00:00:01,000 --> 00:0开发者_如何学Go0:04,000", hour,minutes,seconds,mili seconds.

how do I match this in a string? Im trying to add and subtract the time here.


To perform arithmetic on the time values, you'll want to convert the string representations to integer values.

You can use sscanf to read the numbers from the formatted string, then multiply them together appropriately to get a millisecond value. sscanf returns the number of matches that succeeded, so if the integer value returned is less than the number of fields you expected to match, you know the string doesn't match your input format.


I think sscanf is what you need

0

精彩评论

暂无评论...
验证码 换一张
取 消