为什么我的脚本返回0?

时间:2018-01-26 22:02:18

标签: autoit word-count textselection

此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 _
)

1 个答案:

答案 0 :(得分:2)

如果<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="stop">stop</div> <div id="continue">continue</div> <div id="blue"></div> <div id="red"></div> <div id="green"></div>,那么$selpos[0] = 0会返回一个空字符串,因为您的开头超出范围(StringMid()的第一个位置是StringMid())。

1