PartyPooper Posted November 29, 2005 Posted November 29, 2005 I've written some code that reads a text file and determines the total number of lines in the file ($TotalLines). When displaying the result, I need to add commas to make it more aesthetically pleasing and easier to read (eg: 1,000 instead of 1000 and 100,000 instead of 100000). Currently, I'm using the code below (which is limited to 99,999,999 lines) to add the comma's but does anyone know of a cleaner way to add them? If StringLen($TotalLines) < 4 Then $Samples = $Samples; 0 - 999 ElseIf StringLen($TotalLines) = 4 Then $Samples = StringTrimRight($TotalLines, 3) & "," & StringTrimLeft($TotalLines, 1); 1,000 - 9,999 ElseIf StringLen($TotalLines) = 5 Then $Samples = StringTrimRight($TotalLines, 3) & "," & StringTrimLeft($TotalLines, 2); 10,000 - 99,999 ElseIf StringLen($TotalLines) = 6 Then $Samples = StringTrimRight($TotalLines, 3) & "," & StringTrimLeft($TotalLines, 3); 100,000 - 999,000 ElseIf StringLen($TotalLines) = 7 Then $Samples = StringTrimRight($TotalLines, 6) & "," & StringMid($TotalLines, 2, 3) & "," & StringTrimLeft($TotalLines, 4); 1,000,000 - 9,999,999 ElseIf StringLen($TotalLines) = 8 Then $Samples = StringTrimRight($TotalLines, 6) & "," & StringMid($TotalLines, 3, 3) & "," & StringTrimLeft($TotalLines, 5); 10,000,000 - 99,999,999 EndIf MsgBox(0,"",$Samples " Lines of text in file") I've looked at Burrup's _AddComma function, but I'd rather use a native AutoIt 3 Function or UDF if one is available (by native, I mean one that is included in the distro). Thanks.
Valuater Posted November 29, 2005 Posted November 29, 2005 (edited) well heres a small effort for ya Dim $t = 0, $Final $Totallines = "1234567890" $result = StringSplit($Totallines, "") For $x = $result[0] to 1 step -1 $t = $t + 1 If $t = 4 And $x < $result[0] Then $Final = $result[$x] & "," & $Final $t = 1 ContinueLoop Else $Final = $result[$x] & $Final EndIf Next MsgBox(0,"Final Result", $Final) 8) Edited November 29, 2005 by Valuater
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