REM > Territories:Utilities.SortChars

INPUT "Territory number: "z%

DIM c$(255)

FOR c% = 0 TO 255: c$(c%) = CHR$c%: NEXT

 REPEAT
  d% = TRUE
   FOR c% = 0 TO 254
    SYS &4305D, z%, c$(c%), c$(c%+1) TO a%
    IF a% > 0 THEN d% = FALSE: SWAP c$(c%), c$(c%+1)
   NEXT
 UNTIL d%

INPUT "File name: "f$
f% = OPENOUT f$
FOR c% = 0 TO 255: BPUT#f%, c$(c%);: NEXT
CLOSE#f%

