Jump to content

Recommended Posts

Posted

Is there an other way like this: 

dim $myStringBuff=StringBuff(3)
MsgBox(0, "StringBuff(5)=", $myStringBuff)


;-------------------------------------------------
Func StringBuff( $size, $FillChar="0")
    Local $StringBuffer

    For $i = 1 To $size
        $StringBuffer = $StringBuffer & $FillChar
    Next
    Return $StringBuffer
EndFunc

to easily create a String in Autoit?

Especially 

$StringBuffer = $StringBuffer & $FillChar
is a really bad way to do so regarding the performance.
(each time in the Loop a new string is created and the old one is discarded)
 

Maybe something like this

Local $StringBuffer[$size]
    For $i = 1 To $size
        $StringBuffer[$i] = $FillChar
    Next
        Return $StringBuffer

^-Sample Doesn't work

 
...or
Local $StringBuffer

    For $i = 1 To $size
        _StringAppend($StringBuffer, $FillChar)
    Next
    Return $StringBuffer

were '_StringAppend()' is some Interpreter optimised version that does some kind of redim to $StringBuffer and then append $FillChar

 

  • Moderators
Posted

Robinson1,

Have you come across _StringRepeat in the Help file? if not, I suggest taking a look. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

Robinson1,

Have you come across _StringRepeat in the Help file? if not, I suggest taking a look. ;)

M23

Wow cool _StringRepeat  that's it. Thanks.

I actually looked how it's implementated:

Func _StringRepeat($sString, $iRepeatCount)
;...
            For $iCount = 1 To $iRepeatCount
                $sResult &= $sString
            Next

            Return $sResult
EndFunc

So the core part is this:

$sResult &= $sString

Hmm I guess the  operator '&=' on a string is already linked like to some kinda StringConcat.

Anyway

$sResult &= $sString is more nice than

$sResult = $sResult & $sString.

...so I'll use that construct or _StringRepeat in future. :D

Edited by Robinson1
  • Moderators
Posted

Robinson1,

The function in the Beta version is rather more advanced - and much quicker I am told: ;)

Func _StringRepeat($sString, $iRepeatCount)
    ; Casting Int() takes care of String/Int, Numbers.
    $iRepeatCount = Int($iRepeatCount)
    ; Zero is a valid repeat integer.
    If StringLen($sString) < 1 Or $iRepeatCount < 0 Then Return SetError(1, 0, "")
    Local $sResult = ""
    While $iRepeatCount > 1
        If BitAND($iRepeatCount, 1) Then $sResult &= $sString
        $sString &= $sString
        $iRepeatCount = BitShift($iRepeatCount, 1)
    WEnd
    Return $sString & $sResult
EndFunc   ;==>_StringRepeat
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

I see it's blowing up da string exponentially now.

Nice idea. I'll keep that idea for other languages. :thumbsup:

Its a little hard to see on the first glance  - Maybe that will be a little better readable

Func _StringRepeat($sString, $iRepeatCount)

    ; Casting Int() takes care of String/Int, Numbers.
    $iRepeatCount = Int($iRepeatCount)

    ; Zero is a valid repeat integer.
    If (StringLen($sString) < 1) Or _
       ($iRepeatCount < 0) Then _
            Return SetError(1, 0, "")

    ; Blow up string exponentially
    Local $sResult = ""
    While $iRepeatCount > 1

        ; when RepeatCount is uneven; store rest in $sResult
        If mod($iRepeatCount, 2) Then
            $sResult &= $sString
        EndIf

        ; Concat string exponentially
        $sString &= $sString

        ; Next
        $iRepeatCount = int($iRepeatCount / 2)
    WEnd

    Return $sString & $sResult
EndFunc   ;==>_StringRepeat

^-I also took out that bit crafting stuff even if that might tiny slow down the function.

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...