在AutoIt中重写字符串一次有效,但第二次无效



我正在编写一些AutoIt代码,以帮助我处理办公室恶作剧和其他事情。第一个字符串将字符串"shutdown pc00xxx"重写为shutdown /r /m pc00xxx /t 0,但我无法将第二个字符串重写为re.

我有以下代码:

func RunProc($string)
    Local $command = StringLower($string)
    Local $subs = StringMid($command, 1, 4)
    Local $computer = StringInStr($command, "pc")
    if $subs == "shut" Then
        Run("shutdown /r /m " & StringMid($command, $computer) & " /t 0")
    ElseIf $subs == "clos" Then
        Local $prleft = StringTrimLeft($command, 6)
        Local $extend = StringInStr($command, "on")
        Local $pright = StringTrimRight($prleft, $extend)
        Local $strclose = StringMid($string, $prleft, $pright)
        Run("taskkill.exe /S "& StringMid($command, $computer) & "  /im " & $strclose & ".exe")
    EndIf

问题是,我试图重写短语"CLOSE"SOMETHING"ON"pc00xxx"为taskkill.exe/S pc00xxx/im SOMETHING.exe,我试图获得"CLOSE"one_answers"ON pc00xxx."之间的子字符串。

因此,例如,我将键入CLOSE OUTLOOK ON PC00xxx,并使$strclose的值为:

$strclose = outlook

试试这个:

$string = 'CLOSE OUTLOOK ON PC00xxx'
$aMatch = StringRegExp($string, '(?i)close (.+) on pc.+', 1)
If IsArray($aMatch) Then ConsoleWrite('App: ' & $aMatch[0] & @CRLF)

或者,使用StringSplit:

$string = 'CLOSE OUTLOOK ON PC00xxx'
$stringcomponents=StringSplit(StringStripWS($string,4)," ")
$strclose=$stringcomponents

相关内容

  • 没有找到相关文章

最新更新