为什么我的脚本 return 0?
Why does my script return 0?
这个AutoIt脚本计算字数;字符(带空格和不带空格);线路;以及用户选择的文本的估计说话时间(假设每秒两个词)。
但是,如果输入字符串的起始位置为 0
(在文件顶部的左上角),则方法 returns 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 _
)
If $selpos[0] = 0
then StringMid()
returns 一个空字符串,因为你的开始超出范围(因为 StringMid()
的第一个位置是 1
)。
$sTest = "A sample test string"
MsgBox(0, '' , StringMid($sTest , 0 , 8))
MsgBox(0, '' , StringMid($sTest , 1 , 8))
这个AutoIt脚本计算字数;字符(带空格和不带空格);线路;以及用户选择的文本的估计说话时间(假设每秒两个词)。
但是,如果输入字符串的起始位置为 0
(在文件顶部的左上角),则方法 returns 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 _
)
If $selpos[0] = 0
then StringMid()
returns 一个空字符串,因为你的开始超出范围(因为 StringMid()
的第一个位置是 1
)。
$sTest = "A sample test string"
MsgBox(0, '' , StringMid($sTest , 0 , 8))
MsgBox(0, '' , StringMid($sTest , 1 , 8))