#pragma compile(UPX, True)
#pragma compile(x64, False)
#pragma compile(Console, True)
#pragma compile(FileDescription, 'Случайный участок текста')
Opt('MustDeclareVars', True)
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
Local Const _
$csRExp = '(*UCP)(?isU)(\b\w+\b\W*?)+', _
$ciMax = 4
Local _
$sText = 'В лесу родилась елочка, в лесу она росла. Зимой и летом стройная - всегда она была.', _
$vRes, _
$sExtract, _
$sOutput, _
$iErr, $iErx, _
$i, $j, $k, $iRC = 0
$vRes = StringRegExp($sText, $csRExp, $STR_REGEXPARRAYGLOBALMATCH)
$iErr = @error
$iErx = @extended
If $iErr Then
$sOutput = StringFormat('Облом разбора входного текста\n@error = %d, @extended = %d', $iErr, $iErx)
MsgBox($MB_ICONERROR, @ScriptDir, $sOutput)
Exit
EndIf
$k = UBound($vRes)
Do
$i = Random(1, $k, 1)
$j = Random(1, $ciMax, 1)
$sExtract = i_SelWords($vRes, $i, $j)
ClipPut($sExtract)
$sOutput = StringFormat('From = %u, Count = %u\nResult = "%s"', $i, $j, $sExtract)
$iRC = MsgBox (BitOR($MB_ICONINFORMATION, $MB_OKCANCEL), @ScriptName, $sOutput)
Until $iRC = $IDCANCEL
Exit
Func i_SelWords(ByRef Const $paWords, _
$pi1_st, _
$piCount _
)
Local _
$sResult = '', _
$iLast, _
$iLastMax, _
$i
If Not IsArray($paWords) Then Return SetError(1, 0, $sResult)
If Not IsNumber($pi1_st) Or ($pi1_st < 1) Then Return SetError(2, 0, $sResult)
If Not IsNumber($piCount) Or ($piCount < 1) Then Return SetError(3, 0, $sResult)
$iLast = $pi1_st + $piCount - 1
$iLastMax = UBound($paWords)
For $i = $pi1_st To $iLast
If $i > $iLastMax Then ExitLoop
$sResult &= $paWords[$i-1]
Next
Return $sResult
EndFunc