Jump to content

Recommended Posts

Posted (edited)

_StringRepeatEx UDF by GreenBox (= EcmaXp, Admin At EcmaXp.PE.KR) and UDF doc create and UDF modify by Mat

; #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)
EndFunc

Result 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? True

Result B: by ProgAndy ( #743557 )

- AU3 : Autoit 3.3.0.0

_StringRepeat >>> 230 ms
_StringRepeatEx >>> 1 ms
Is $vResultA = $vResultB? True

Result C: by ProgAndy ( Same link "Result B" )

- AU3 : AutoIt 3.3.1.5

_StringRepeat >>> 238 ms
_StringRepeatEx >>> 2 ms
Is $vResultA = $vResultB? True

Result 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? True

This post from #743550

Edited by GreenBox

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...