GreenBox Posted November 11, 2009 Posted November 11, 2009 (edited) _StringRepeatEx UDF by GreenBox (= EcmaXp, Admin At EcmaXp.PE.KR) and UDF doc create and UDF modify by Matexpandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name...........: _StringRepeatEx ; Description ...: Repeats a string a specified number of times. ; Syntax.........: _StringRepeatEx($sString, $iRepeatCount) ; Parameters ....: $sString - String to repeat ; $iRepeatCount - Number of times to repeat the string ; Return values .: Success - Returns string with specified number of repeats ; Failure - Returns an empty string and sets @error to non-zero or returns an not empty string and sets @extended = 1 ; |@Error - 0 = No error. ; |@Error - 1 = $iRepeatCount is not a number ; |@Error - 2 = $sString is too short - "" ; |@Error - 3 = $iRepeatCount is less than zero ; |@Extended - 1 = $iRepeatCount is too large number ; Author ........: EcmaXp (Admin At EcmaXp.PE.KR) ; Modified.......: Mat ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _StringRepeatEx($sString, $iRepeatCount) If Not StringIsInt($iRepeatCount) Then Return SetError(1, 0, "") If StringLen($sString) < 1 Then Return SetError(2, 0, "") If $iRepeatCount <= 0 Then Return SetError(3, 0, "") If $iRepeatCount = 1 Then Return $sString Local $bLarge = False, $nResultLen = StringLen($sString) * $iRepeatCount If $nResultLen >= 2 ^ 27 Then $bLarge = True If $bLarge Then $nResultLen = 2 ^ 27 - 1 While StringLen($sString) * 2 <= $nResultLen $sString &= $sString WEnd $sString &= StringLeft($sString, $nResultLen - StringLen($sString)) Return SetExtended($bLarge, $sString) EndFunc ;==>_StringRepeatEx_StringRepeatEx UDF Example (old)#include <String.au3> Global $vResultA, $vResultB $vResultA = ChkTimer(TimerInit(), _StringRepeat("-", 2^18)) ConsoleWrite("_StringRepeat >>> " & @extended & " ms" & @CRLF) $vResultB = ChkTimer(TimerInit(), _StringRepeatEx("-", 2^18)) ConsoleWrite("_StringRepeatEx >>> " & @extended & " ms" & @CRLF) ConsoleWrite("Is $vResultA = $vResultB? " & ($vResultA = $vResultB) & @CRLF) Func _StringRepeatEx($sString, $iRepeatCount) ;OLD FUNC Local $nResultLen = StringLen($sString) * $iRepeatCount If $nResultLen >= 2^27 Then $nResultLen = 2^27 - 1 ;Limit String Variant Do $sString &= $sString Until StringLen($sString) >= $nResultLen Return StringLeft($sString, $nResultLen) EndFunc Func ChkTimer($iTime, $vResult) Return SetExtended(TimerDiff($iTime), $vResult) EndFuncResult A: by me ( This post ) - AU3 : Autoit 3.3.0.0 - CPU : IntelĀ® CeleronĀ® CPU 2.40GHz - RAM : 768 MB - O S : Microsoft Windows 7 Ultimate K_StringRepeat >>> 5969 ms _StringRepeatEx >>> 5 ms Is $vResultA = $vResultB? TrueResult B: by ProgAndy ( #743557 ) - AU3 : Autoit 3.3.0.0_StringRepeat >>> 230 ms _StringRepeatEx >>> 1 ms Is $vResultA = $vResultB? TrueResult C: by ProgAndy ( Same link "Result B" ) - AU3 : AutoIt 3.3.1.5_StringRepeat >>> 238 ms _StringRepeatEx >>> 2 ms Is $vResultA = $vResultB? TrueResult D: by Malkey ( #743944 ) - AU3 : Autoit 3.3.0.0 - UDF : ORIGINAL, _StringRepeatExMod, _StringRepeatMod_StringRepeat >>> 2079 ms _StringRepeatEx >>> 10 ms _StringRepeatExMod >>> 10 ms _StringRepeatMod >>> 10 ms Is $vResultA = $vResultB? True Is $vResultA = $vResultC? True Is $vResultA = $vResultD? TrueThis post from #743550 Edited November 11, 2009 by GreenBox
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now