Moderators SmOke_N Posted October 22, 2006 Moderators Posted October 22, 2006 (edited) Derived from Gary bringing up an old post on _Addcomma() and saying it could probably be done shorter now. (Not thoroughly tested)expandcollapse popup;================================================================================================== ; Function Name: _StrAddComma($sStr, $sSeperator, $sEnd) ; ; Parameters: $sStr: The Numbered string to pass ; $sSeperator: The seperator string you wish to use as the delimeter ; Default or -1: ',' ; $sEnd: The End delimeter to distinguish decimal remainder ; Default or -1: '.' ; ; Description: Adds your preferred delimeter to a Number string ; ; Requirement(s) AuotIt Beta 3.2.1.8 or higher ; ; Return Value(s) On Success: @Error: = 0 No Error | Returns the number string with its sperators ; On Failure: @Error = 1: String passed was not a number ; ; Author(s): SmOke_N ;================================================================================================== Func _StrAddComma($sStr, $sSeperator = -1, $sEnd = -1) If $sSeperator = -1 Or $sSeperator = Default Then $sSeperator = ',' If $sEnd = -1 Or $sEnd = Default Then $sEnd = '.' Local $aNum = StringSplit($sStr, $sEnd), $nHold, $aSRE, $fUB, $iAdd If UBound($aNum) > 2 Then $aSRE = StringRegExp($aNum[1], '(\d+)(\d{3})', 3) $fUB = True Else $aSRE = StringRegExp($sStr, '(\d+)(\d{3})', 3) EndIf If UBound($aSRE) = 2 Then While IsArray($aSRE) $nHold = $sSeperator & $aSRE[1] & $nHold $aSRE = StringRegExp($aSRE[0], '(\d+)(\d{3})', 3) $iAdd += 1 WEnd EndIf If $fUB And $nHold Then Return SetError(0, 0, StringTrimRight($sStr, ($iAdd + 1) * 3) & $nHold & $sEnd & $aNum[2]) ElseIf $nHold Then Return SetError(0, 0, StringTrimRight($sStr, $iAdd * 3) & $nHold) EndIf Return SetError(1, 0, $sStr) EndFunc Damn Edits got so big, gave them a codebox CODE Edit: Fixed Return Error Edit2: Had to remove StringIsFloat/StringIsInt arguement. Edit3: Shortened to 21 lines. Edit4: Fixed a bug that xcal noticed... Thanks Edit5: Last fix that I did xcal noticed, broke the decimal return, that's fixed now. Edit6: Edited for submission. Edited October 22, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
cppman Posted October 22, 2006 Posted October 22, 2006 Nice. I like it. .. now, if you can write this for me in C++ . lol Miva OS Project
Moderators SmOke_N Posted October 22, 2006 Author Moderators Posted October 22, 2006 Nice. I like it... now, if you can write this for me in C++ . lolShould be easier and smaller. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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