home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 August / PCWorld_2000-08_cd.bin / Software / TemaCD / xbasic / xbpro.exe / xb / atrim.x < prev    next >
Text File  |  1999-12-29  |  3KB  |  144 lines

  1. '
  2. ' ####################
  3. ' #####  PROLOG  #####
  4. ' ####################
  5. '
  6. ' This program demonstrates the LTRIM$(), RTRIM$(), TRIM$() intrinsics,
  7. ' and also the XstLTRIM(), XstRTRIM(), XstTRIM() library functions.
  8. ' See comments in function Entry() for details.
  9. '
  10. '
  11. PROGRAM    "atrim"
  12. VERSION    "0.0000"
  13. '
  14. IMPORT "xst"
  15. IMPORT "xui"
  16. '
  17. DECLARE FUNCTION  Entry ()
  18. '
  19. '
  20. ' ######################
  21. ' #####  Entry ()  #####
  22. ' ######################
  23. '
  24. ' The LTRIM$(), RTRIM$(), TRIM$() intrinsics trim
  25. ' all characters with values <= 0x20 and >= 0x80 .
  26. ' This generally works fine for English, but may
  27. ' trim characters valid/desired in other languages.
  28. '
  29. ' The XstLTRIM(), XstRTRIM(), XstTRIM() functions
  30. ' accept an XLONG array argument to specify which
  31. ' characters should be trimmed.  Only characters
  32. ' with zero in the corresponding array location
  33. ' are trimmed by these functions.
  34. '
  35. FUNCTION  Entry ()
  36. '
  37. ' create array for XstLTRIM(), XstRTRIM(), XstTRIM()
  38. '
  39.     DIM array[255]                            ' array to hold trim characters
  40. '
  41.     FOR i = 0 TO 255                        ' for all characters
  42.         array[i] = i                            '    trim nothing except 0x00 - null character
  43.     NEXT i
  44. '
  45. ' set array to trim only four characters and no others
  46. '
  47.     array[' '] = 0                            ' trim space characters
  48.     array['\t'] = 0                            ' trim tab characters
  49.     array[0x00] = 0                            ' trim null characters
  50.     array[0xFF] = 0                            ' trim character 255
  51. '
  52. ' create some test strings
  53. '
  54.     upper = 47
  55.     DIM s$[upper]
  56. '
  57.     s$[00] = "xxxxxxxxx"
  58.     s$[01] = " xxxxxxxx"
  59.     s$[02] = "  xxxxxxx"
  60.     s$[03] = "xxxxxxxx "
  61.     s$[04] = "xxxxxxx  "
  62.     s$[05] = " xxxxxxx "
  63.     s$[06] = "  xxxxx  "
  64.     s$[07] = "  xx xx  "
  65. '
  66.     s$[08] = "xxxxxxxxx"
  67.     s$[09] = "\txxxxxxxx"
  68.     s$[10] = "\t\txxxxxxx"
  69.     s$[11] = "xxxxxxxx\t"
  70.     s$[12] = "xxxxxxx\t\t"
  71.     s$[13] = "\txxxxxxx\t"
  72.     s$[14] = "\t\txxxxx\t\t"
  73.     s$[15] = "\t\txx\txx\t\t"
  74. '
  75.     s$[16] = "xxxxxxxxx"
  76.     s$[17] = "\0xxxxxxxx"
  77.     s$[18] = "\0\0xxxxxxx"
  78.     s$[19] = "xxxxxxxx\0"
  79.     s$[20] = "xxxxxxx\0\0"
  80.     s$[21] = "\0xxxxxxx\0"
  81.     s$[22] = "\0\0xxxxx\0\0"
  82.     s$[23] = "\0\0xx\0xx\0\0"
  83. '
  84.     s$[24] = "xxxxxxxxx"
  85.     s$[25] = "\xFFxxxxxxxx"
  86.     s$[26] = "\xFF\xFFxxxxxxx"
  87.     s$[27] = "xxxxxxxx\xFF"
  88.     s$[28] = "xxxxxxx\xFF\xFF"
  89.     s$[29] = "\xFFxxxxxxx\xFF"
  90.     s$[30] = "\xFF\xFFxxxxx\xFF\xFF"
  91.     s$[31] = "\xFF\xFFxx\xFFxx\xFF\xFF"
  92. '
  93.     s$[32] = "xxxxxxxxx"
  94.     s$[33] = "\x10xxxxxxxx"
  95.     s$[34] = "\x10\x10xxxxxxx"
  96.     s$[35] = "xxxxxxxx\x10"
  97.     s$[36] = "xxxxxxx\x10\x10"
  98.     s$[37] = "\x10xxxxxxx\x10"
  99.     s$[38] = "\x10\x10xx\x10xx\x10\x10"
  100.     s$[39] = "\x10\x10xx\x10xx\x10\x10"
  101. '
  102.     s$[40] = "xxxxxxxxx"
  103.     s$[41] = "\xA0xxxxxxxx"
  104.     s$[42] = "\xA0\xA0xxxxxxx"
  105.     s$[43] = "xxxxxxxx\xA0"
  106.     s$[44] = "xxxxxxx\xA0\xA0"
  107.     s$[45] = "\xA0xxxxxxx\xA0"
  108.     s$[46] = "\xA0\xA0xx\xA0xx\xA0\xA0"
  109.     s$[47] = "\xA0\xA0xx\xA0xx\xA0\xA0"
  110. '
  111. ' show what each function does
  112. '
  113.     PRINT
  114.     PRINT "::: note ::: tab characters disturb the column alignment in some rows"
  115.     PRINT
  116.     PRINT "              LTRIM$()/XstLTRIM   RTRIM$()/XstRTRIM   TRIM$()/XstTRIM"
  117. '
  118.     FOR i = 0 TO upper
  119.         string$ = s$[i]
  120.         a$ = LTRIM$ (string$)
  121.         b$ = RTRIM$ (string$)
  122.         c$ = TRIM$ (string$)
  123. '
  124.         d$ = string$
  125.         e$ = string$
  126.         f$ = string$
  127. '
  128.         XstLTRIM (@d$, @array[])
  129.         XstRTRIM (@e$, @array[])
  130.         XstTRIM (@f$, @array[])
  131. '
  132.         PRINT "intrinsic :   ";
  133.         PRINT LJUST$ ("<" + a$ + ">", 20);
  134.         PRINT LJUST$ ("<" + b$ + ">", 20);
  135.         PRINT LJUST$ ("<" + c$ + ">", 20)
  136.         PRINT "functions :   ";
  137.         PRINT LJUST$ ("<" + d$ + ">", 20);
  138.         PRINT LJUST$ ("<" + e$ + ">", 20);
  139.         PRINT LJUST$ ("<" + f$ + ">", 20)
  140. '        PRINT
  141.     NEXT i
  142. END FUNCTION
  143. END PROGRAM
  144.