home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / ibm1 / do101j2.arj / STRINGS.SCR < prev    next >
Encoding:
Text File  |  1992-03-15  |  5.5 KB  |  178 lines

  1. .pg wi full clr
  2. /FRAME ~179 ~196 ~217 ~191 ~192 ~218
  3. /BOX 20 1 60 20
  4. /DRAW V 61 2 21 0 ░
  5. /DRAW H 21 21 61 0 ░
  6. .wi 21 2 59 19 ye
  7.     S T R I N G   F U N C T I O N S
  8. .wi 22 4 58 19 #
  9. »%t«DO»#« has several functions which allow
  10. you to manipulate strings. These
  11. functions can be used any place
  12. where »wh«variables are expanded»#«.
  13.  
  14. Functions start with '»+ye«@»#«' and take
  15. the general form:
  16. »ye«
  17.  @»cy«{function}({param1},{param1},...)
  18. »#«
  19. .pg 24 clr
  20. »ye«
  21.  @»cy«{function}({param1},{param1},...)
  22. »#«
  23. The »cy«{function}»#«'s are:
  24.  
  25.   »ye«cpy  »gy«=»#« copy part of a string
  26.   »ye«del  »gy«=»#« delete part of a string
  27.   »ye«ins  »gy«=»#« insert one string in
  28.          another string
  29.   »ye«len  »gy«=»#« get the length of a string
  30.   »ye«pos  »gy«=»#« find the position of one
  31.         string in another string
  32.   »ye«trim »gy«=»#« trim unwanted characters
  33.          from the string
  34.   »ye«pad  »gy«=»#« pad string with spaces
  35. .pg clr go 1 5
  36. The following screens present each
  37. of the functions in detail.
  38. /FRAME RESET
  39. .pg -24 wi full clr cy
  40.     FUNCTION NAME»gray«: »%t« CopyString »cy«
  41.  
  42.     ~064cpy({string},{start},{length})
  43. /cw
  44.  
  45. The »%t«CopyString»#« function returns a portion of »cy«{string}»#« starting at
  46. »cy«{start}»#« for a length of »cy«{length}»#«. The following examples are
  47. shown before they are executed. Press »bo«<enter>»#« to execute the
  48. example:
  49.  
  50. |/SET String 1234567890
  51. |This is part of the string: @cpy(%string,2,4).
  52.  
  53. Strings containing commas (",") have to be enclosed in quotes:
  54.  
  55. |This is part of a string: @cpy("Ted, Bill, and I . . .",6,4).
  56.  
  57. .pg wi full clr cy
  58.     FUNCTION NAME»gray«: »%t« DeleteString »cy«
  59.  
  60.     ~064del({string},{start},{length})
  61. /cw
  62.  
  63. The »%t«DeleteString»#« function deletes a portion of »cy«{string}»#« starting
  64. at »cy«{start}»#« for a length of »cy«{length}»#«.  Here are a couple of examples.
  65. Press »bo«<enter>»#« to execute each after you have examined them.
  66.  
  67. |This is part of a string: @del(1234567890,4,2).
  68.  
  69. |/SET Result @del(1234567890,4,3)
  70. |This is the result: %result
  71. .pg wi full clr cy
  72.     FUNCTION NAME»gray«: »%t« InsertString »cy«
  73.  
  74.     ~064ins({string},{target},{position})
  75. /cw
  76.  
  77. Insert »cy«{target}»#« into »cy«{string}»#« before »cy«{position}»#«.
  78.  
  79. Here are some examples:
  80.  
  81. |This is a longer string: @ins(1234567890,»bo«ABC»#«,7)
  82.                               ^   »+re«^»cy«{Position}»#«
  83.  
  84. Notice that the string is inserted »ye«BEFORE »cy«{position}»#« pushing
  85. everything from »cy«{position}»#« to the right.
  86.  
  87. |/SET String DEFG
  88. |Here is %string inserted in another string:  @ins(1234567890,%string,2)
  89. .pg wi full clr cy
  90.     FUNCTION NAME»gray«: »%t« LengthString »cy«
  91.  
  92.     ~064len({string})
  93. /cw
  94.  
  95. Returns the length of »cy«{string}»#«.
  96.  
  97. Here are some examples. Press »bo«<enter>»#« to execute them.
  98.  
  99. |/SET string 1234567890
  100. |Length of %string = @len(%string)
  101.  
  102. The »%t«LengthString»#« function is often  used in conjunction with
  103. other functions:
  104.  
  105. |Here is an example: @del(%string,1,@len(%string)/2)
  106.  
  107. .pg wi full clr cy
  108.     FUNCTION NAME»gray«: »%t« PositionString »cy«
  109.  
  110.     ~064pos({string},{target})
  111. /cw
  112.  
  113. Returns the position of the first occurrence of »cy«{target}»#« in
  114. »cy«{string}»#«.
  115.  
  116. Here are some examples.  Press »bo«<enter>»#« to execute each line.
  117.  
  118. |/set string ABCDEFGHIJK
  119.  
  120. |Position of DEF = @pos(%string,DEF)
  121.  
  122. PositionString, like LengthString is often used in conjunction
  123. with other functions:
  124.  
  125. |/set string test.txt
  126. |Backup file %string = @cpy(%string,1,@pos(%string,"."))BAK
  127.  
  128. .pg wi full clr cy
  129.     FUNCTION NAME»gray«: »%t« TrimString »cy«
  130.  
  131.     ~064trim({string}[,{target},L|R|B])
  132. /cw
  133.     Removes unwanted characters (»cy«{target}»#«) from the »wh«end»#«(s) of
  134.     »cy«{string}»#«.
  135.  
  136.     »cy«{target}»#« is evaluated »gr«AS IS»#«. That is "»wh«a»#«" is diffent from "»wh«A»#«".
  137.     »cy«L »gy«=»#« Trims the start of the string (»wh«left»#«)
  138.     »cy«R »gy«=»#« Trims the end of the string (»wh«right»#«)
  139.     »cy«B »gy«=»#« Trims »wh«both ends»#« of the string.
  140.  
  141.     If just the »cy«{string}»#« is entered [i.e. »ye«~064trim({string})»#«] then
  142.     spaces are trimmed from both ends of the string.
  143.  
  144. .pg clr
  145.     Here are some examples.  Press »bo«<enter>»#« to execute each.
  146.  
  147. |/set string "  abcdeABCDEabcde  "
  148.     »cy«Original String [»wh«%string»cy«]»#«
  149. |    [@trim(%string," abde",B)]
  150. |    [@trim(%string," ",L)]
  151. |    [@trim(%string," e",R)]
  152. |    [@trim(%string," E",R)]
  153.         Notice that "»ye«E»#«" gives different results than "»ye«e»#«"
  154. |/SET string2 @trim(@trim(%string," ",B),"abcdefghijklmnopqrstuvwxyz",b)
  155.     [%string2]
  156.         The first »%t«TrimString»#« function removes »wh«spaces»#«.  The second
  157.         function removes all »wh«lower case letters»#«.
  158.         Notice that »re«CAPITAL»#« letters are not removed.
  159. .pg wi full clr cy
  160.     FUNCTION NAME»gray«: »%t« PadString »cy«
  161.  
  162.     ~064pad({string},{length},[L|R|C])
  163. /cw
  164.     Pads »cy«{string}»#« with spaces to »cy«{length}»#«.  If the justification
  165.     is not included "»cy«L|R|C»#«" then the string will be »ye«LEFT»#«
  166.     justified and padded with spaces on the right.
  167.  
  168.     Here are some examples:
  169.  
  170. /SET string TEST
  171. |Here is '»ye«%string»#«' left justified: '»ye«@pad(%string,20)»#«'.
  172. |Here is '»ye«%string»#«' left justified: '»ye«@pad(%string,20,L)»#«'.
  173. »bl«NOTE»gy«:»wh« the default justification if left justified.»#«
  174.  
  175. |Here is '»ye«%string»#«' right justified: '»ye«@pad(%string,20,R)»#«'.
  176. |Here is '»ye«%string»#«' centered       : '»ye«@pad(%string,20,C)»#«'.
  177. /ENDEXEC CLEAR
  178.