home *** CD-ROM | disk | FTP | other *** search
/ GameStar 1998 November (Bonus) / GAMESTAR11B.ISO / ENCYC99 / MM / T620272A.DCR / Scripts_13_TextTools.ls < prev    next >
Encoding:
Text File  |  1998-06-29  |  1.4 KB  |  57 lines

  1. on addCommas xInt
  2.   set finalString to string(xInt)
  3.   set moreChars to (3 - (the number of chars in finalString mod 3)) mod 3
  4.   repeat with i = 1 to moreChars
  5.     put " " before finalString
  6.   end repeat
  7.   set groupsOfThree to []
  8.   set groupCount to the number of chars in finalString / 3
  9.   repeat with i = 0 to groupCount - 1
  10.     set thisStart to i * 3
  11.     set thisGroupString to EMPTY
  12.     repeat with j = 1 to 3
  13.       put char thisStart + j of finalString after thisGroupString
  14.     end repeat
  15.     add(groupsOfThree, thisGroupString)
  16.   end repeat
  17.   setAt(groupsOfThree, 1, string(value(getAt(groupsOfThree, 1))))
  18.   set finalString to EMPTY
  19.   repeat with i in groupsOfThree
  20.     put i & " " after finalString
  21.   end repeat
  22.   delete char -30000 of finalString
  23.   return finalString
  24. end
  25.  
  26. on removeCommas xString
  27.   set finalString to xString
  28.   repeat with i = 1 to the number of chars in finalString
  29.     set thisChar to char i of finalString
  30.     if thisChar > "9" then
  31.       return #error
  32.       next repeat
  33.     end if
  34.     if thisChar < "0" then
  35.       if thisChar = " " then
  36.         delete char i of finalString
  37.         next repeat
  38.       end if
  39.       return #error
  40.     end if
  41.   end repeat
  42.   return finalString
  43. end
  44.  
  45. on moneyToInteger xString
  46.   set tempString to xString
  47.   delete char 1 of tempString
  48.   delete char 1 of tempString
  49.   return integer(removeCommas(tempString))
  50. end
  51.  
  52. on moneyFormat xInt
  53.   set finalString to addCommas(xInt)
  54.   put "DM " before finalString
  55.   return finalString
  56. end
  57.