【发布时间】:2018-07-06 07:35:04
【问题描述】:
这个 AutoIt 脚本计算字数;字符(带和不带空格);线条;以及用户选择的文本的预计说话时间(假设每秒两个单词)。
但是,如果输入字符串的起始位置是0(在文件顶部的左上角),则该方法对所有内容都返回0,即使主函数运行良好。
我不知道为什么。
$input_str = GUICtrlRead($Textbox)
$selpos = _GUICtrlEdit_GetSel($Textbox)
MsgBox($MB_OK, $selpos[0], $selpos[1])
$selstring = StringMid($input_str, $selpos[0], ($selpos[1] - $selpos[0]))
$WordArray = StringRegExp($selstring, "[\s\.:;,]*([a-zA-Z0-9-_]+)[\s\.:;,]*", 3)
$SingleQuotes = StringRegExp($selstring, "'", 3)
$Result = ""
$Seconds = (UBound($WordArray) - UBound($SingleQuotes)) / 2
If $Seconds >= 3600 Then
If $Seconds / 3600 >= 2 Then
$Result = $Result & Int($Seconds / 3600) & " hours "
Else
$Result = $Result & Int($Seconds / 3600) & " hour "
EndIf
EndIf
If Mod($Seconds, 3600) >= 60 Then
If $Seconds / 60 >= 2 Then
$Result = $Result & Int(Mod($Seconds, 3600) / 60) & " minutes "
Else
$Result = $Result & Int(Mod($Seconds, 3600) / 60) & " minute "
EndIf
EndIf
If Mod($Seconds, 60) > 0 Then
If Mod($Seconds, 60) >= 2 Then
$Result = $Result & Int(Mod($Seconds, 60)) & " seconds "
Else
$Result = $Result & Int(Mod($Seconds, 60)) & " second "
EndIf
EndIf
MsgBox($MB_OK, "Selection Properties", _
"Number of characters (with spaces): " & StringLen($selstring) & @CRLF & _
"Number of Characters (without spaces): " & StringLen(StringStripWS($selstring, 8)) & @CRLF & _
"Number of words: " & (UBound($WordArray) - UBound($SingleQuotes)) & @CRLF & _
"Number of lines: " & _GUICtrlEdit_GetLineCount($selstring) & @CRLF & _
"Estimated speaking time: " & $Result _
)
【问题讨论】:
标签: autoit word-count textselection