home *** CD-ROM | disk | FTP | other *** search
- .pg wi full clr
- /FRAME ~179 ~196 ~217 ~191 ~192 ~218
- /BOX 20 1 60 20
- /DRAW V 61 2 21 0 ░
- /DRAW H 21 21 61 0 ░
- .wi 21 2 59 19 ye
- S T R I N G F U N C T I O N S
- .wi 22 4 58 19 #
- »%t«DO»#« has several functions which allow
- you to manipulate strings. These
- functions can be used any place
- where »wh«variables are expanded»#«.
-
- Functions start with '»+ye«@»#«' and take
- the general form:
- »ye«
- @»cy«{function}({param1},{param1},...)
- »#«
- .pg 24 clr
- »ye«
- @»cy«{function}({param1},{param1},...)
- »#«
- The »cy«{function}»#«'s are:
-
- »ye«cpy »gy«=»#« copy part of a string
- »ye«del »gy«=»#« delete part of a string
- »ye«ins »gy«=»#« insert one string in
- another string
- »ye«len »gy«=»#« get the length of a string
- »ye«pos »gy«=»#« find the position of one
- string in another string
- »ye«trim »gy«=»#« trim unwanted characters
- from the string
- »ye«pad »gy«=»#« pad string with spaces
- .pg clr go 1 5
- The following screens present each
- of the functions in detail.
- /FRAME RESET
- .pg -24 wi full clr cy
- FUNCTION NAME»gray«: »%t« CopyString »cy«
-
- ~064cpy({string},{start},{length})
- /cw
-
- The »%t«CopyString»#« function returns a portion of »cy«{string}»#« starting at
- »cy«{start}»#« for a length of »cy«{length}»#«. The following examples are
- shown before they are executed. Press »bo«<enter>»#« to execute the
- example:
-
- |/SET String 1234567890
- |This is part of the string: @cpy(%string,2,4).
-
- Strings containing commas (",") have to be enclosed in quotes:
-
- |This is part of a string: @cpy("Ted, Bill, and I . . .",6,4).
-
- .pg wi full clr cy
- FUNCTION NAME»gray«: »%t« DeleteString »cy«
-
- ~064del({string},{start},{length})
- /cw
-
- The »%t«DeleteString»#« function deletes a portion of »cy«{string}»#« starting
- at »cy«{start}»#« for a length of »cy«{length}»#«. Here are a couple of examples.
- Press »bo«<enter>»#« to execute each after you have examined them.
-
- |This is part of a string: @del(1234567890,4,2).
-
- |/SET Result @del(1234567890,4,3)
- |This is the result: %result
- .pg wi full clr cy
- FUNCTION NAME»gray«: »%t« InsertString »cy«
-
- ~064ins({string},{target},{position})
- /cw
-
- Insert »cy«{target}»#« into »cy«{string}»#« before »cy«{position}»#«.
-
- Here are some examples:
-
- |This is a longer string: @ins(1234567890,»bo«ABC»#«,7)
- ^ »+re«^»cy«{Position}»#«
-
- Notice that the string is inserted »ye«BEFORE »cy«{position}»#« pushing
- everything from »cy«{position}»#« to the right.
-
- |/SET String DEFG
- |Here is %string inserted in another string: @ins(1234567890,%string,2)
- .pg wi full clr cy
- FUNCTION NAME»gray«: »%t« LengthString »cy«
-
- ~064len({string})
- /cw
-
- Returns the length of »cy«{string}»#«.
-
- Here are some examples. Press »bo«<enter>»#« to execute them.
-
- |/SET string 1234567890
- |Length of %string = @len(%string)
-
- The »%t«LengthString»#« function is often used in conjunction with
- other functions:
-
- |Here is an example: @del(%string,1,@len(%string)/2)
-
- .pg wi full clr cy
- FUNCTION NAME»gray«: »%t« PositionString »cy«
-
- ~064pos({string},{target})
- /cw
-
- Returns the position of the first occurrence of »cy«{target}»#« in
- »cy«{string}»#«.
-
- Here are some examples. Press »bo«<enter>»#« to execute each line.
-
- |/set string ABCDEFGHIJK
-
- |Position of DEF = @pos(%string,DEF)
-
- PositionString, like LengthString is often used in conjunction
- with other functions:
-
- |/set string test.txt
- |Backup file %string = @cpy(%string,1,@pos(%string,"."))BAK
-
- .pg wi full clr cy
- FUNCTION NAME»gray«: »%t« TrimString »cy«
-
- ~064trim({string}[,{target},L|R|B])
- /cw
- Removes unwanted characters (»cy«{target}»#«) from the »wh«end»#«(s) of
- »cy«{string}»#«.
-
- »cy«{target}»#« is evaluated »gr«AS IS»#«. That is "»wh«a»#«" is diffent from "»wh«A»#«".
- »cy«L »gy«=»#« Trims the start of the string (»wh«left»#«)
- »cy«R »gy«=»#« Trims the end of the string (»wh«right»#«)
- »cy«B »gy«=»#« Trims »wh«both ends»#« of the string.
-
- If just the »cy«{string}»#« is entered [i.e. »ye«~064trim({string})»#«] then
- spaces are trimmed from both ends of the string.
-
- .pg clr
- Here are some examples. Press »bo«<enter>»#« to execute each.
-
- |/set string " abcdeABCDEabcde "
- »cy«Original String [»wh«%string»cy«]»#«
- | [@trim(%string," abde",B)]
- | [@trim(%string," ",L)]
- | [@trim(%string," e",R)]
- | [@trim(%string," E",R)]
- Notice that "»ye«E»#«" gives different results than "»ye«e»#«"
- |/SET string2 @trim(@trim(%string," ",B),"abcdefghijklmnopqrstuvwxyz",b)
- [%string2]
- The first »%t«TrimString»#« function removes »wh«spaces»#«. The second
- function removes all »wh«lower case letters»#«.
- Notice that »re«CAPITAL»#« letters are not removed.
- .pg wi full clr cy
- FUNCTION NAME»gray«: »%t« PadString »cy«
-
- ~064pad({string},{length},[L|R|C])
- /cw
- Pads »cy«{string}»#« with spaces to »cy«{length}»#«. If the justification
- is not included "»cy«L|R|C»#«" then the string will be »ye«LEFT»#«
- justified and padded with spaces on the right.
-
- Here are some examples:
-
- /SET string TEST
- |Here is '»ye«%string»#«' left justified: '»ye«@pad(%string,20)»#«'.
- |Here is '»ye«%string»#«' left justified: '»ye«@pad(%string,20,L)»#«'.
- »bl«NOTE»gy«:»wh« the default justification if left justified.»#«
-
- |Here is '»ye«%string»#«' right justified: '»ye«@pad(%string,20,R)»#«'.
- |Here is '»ye«%string»#«' centered : '»ye«@pad(%string,20,C)»#«'.
- /ENDEXEC CLEAR
-