Robinson1 Posted November 30, 2013 Share Posted November 30, 2013 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2013 Moderators Share Posted November 30, 2013 Robinson1,Have you come across _StringRepeat in the Help file? if not, I suggest taking a look. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Robinson1 Posted November 30, 2013 Author Share Posted November 30, 2013 (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. Edited November 30, 2013 by Robinson1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2013 Moderators Share Posted November 30, 2013 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 ;==>_StringRepeatM23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Robinson1 Posted November 30, 2013 Author Share Posted November 30, 2013 I see it's blowing up da string exponentially now. Nice idea. I'll keep that idea for other languages. 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. Link to comment Share on other sites More sharing options...
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