home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / sbasics.lbr / XLATE.BZS / XLATE.BAS
Encoding:
BASIC Source File  |  1993-10-25  |  1.4 KB  |  44 lines

  1.  
  2. comment
  3.            This is a demonstration of the Sbasic ' XLATE ' function
  4.          which will, in this example;
  5.  
  6.         1) convert Upper Case to lower case
  7.         2) leave all punctuation (except <"> ) alone
  8.         3) filter out all control characters by
  9.              converting them to spaces
  10.  
  11.          The secret of this useful (?) function is that ' XLATE '
  12.          takes the ascii value of each character in the <source>
  13.          string and uses this value for its index into the 
  14.          <table> string.   I suppose this might be used to 
  15.          translate between different character sets, ie: ascii to
  16.          ebcdic or ascii to APL .
  17.  
  18. end of comment 
  19.            
  20.  
  21. rem   (set up variables)
  22.  
  23. var  table     ;          table string for translation
  24.      source    ;         source string for translation
  25.      result    ;         result string of  translation
  26.        =string :128
  27.  
  28. rem  (32 spaces & new character set with UC and LC swapped )
  29.  
  30.      table=space$(32)+"!`#$%&'()*+,-./0123456789:;<=>?@"
  31.      table=table+"abcdefghijklmnopqrstuvwxyz[\]^_~"
  32.      table=table+"ABCDEFGHIJKLMNOPQRSTUVWXYZ{|} "
  33.  
  34. rem        get <source> and XLATE to <result> (^c to end)
  35.  
  36.   0start    print "enter text ";
  37.  
  38.               input2 source
  39.                  if source="\" then end
  40.                 result=xlate(source,table)
  41.               print result
  42.  
  43.   goto 0start
  44.