SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index

6.4.26 PIECES(str_expr1 [,str_expr2])

and

6.4.27 PIECE$(str_expr1,num_expr[,str_expr2])

PIECE$ returns an element from str_expr1 specified by num_expr. str_expr1 contains a list of elements. The separator can be indicated by str_expr2. The default separator is a carriage-return line-feed pair.

These two functions are similar to the ELEMENTS() and ELEMENT$() functions except that:

Example 6-81 PIECE$ function

  message 'Enter in a long line of text to be rewrapped. Then click DONE' 
  line input area 5, 10, 8, 60: text$ 
  print at 10, 1: 'Rewrapped text' 
  wt$ = wrap$(text$, 1, 30) 
  print 'Number of lines: '; pieces(wt$) 
  print wt$ 
  print
  print 'First line was: '; piece$(wt$, 1) 
  end
  
  
          +------------------------------------------+ 
          |This line of text is long enough to be    | 
          |rewrapped into more than one line.        | 
          |                                          | 
          |                                          | 
          +------------------------------------------+ 
                 Done    Back   Exit   Help 
                 
                 
                 
   Enter in a long line of text to be rewrapped. Then click DONE. 
                 
                 
           This line of text is long enough to be rewrapped into 
           more than one line. 
           
           
           
Rewrapped text 
Number of lines:  3 
This text is long 
enough to be rewrapped into 
more than one line. 
 
First line was: This text is long 

6.4.28 PRETTY$(str_expr)

PRETTY$ converts text so that the text displays on any terminal. Named control characters show up with their names. Other control characters show up as {X} where "X" is the letter to press or as {XX} where "XX" is the hexadecimal value of the character.

Example 6-82 PRETTY$ function

  a$ = 'Hello' + chr$(5) + chr$(161) + chr$(7) 
  print pretty$(a$) 
  end
 
 
Hello{^E}{A1}{bel} 

6.4.29 QUOTE$(str_expr)

The QUOTE$ function encloses a string expression in double quotes. If the string expression is already enclosed in double quotes, QUOTE$ leaves it alone. If the string expression is already wrapped in single quotes, QUOTE$ replaces them with double quotes. Elements double-quoted within the string expression are given another pair of double quotes (see following example). Elements single-quoted within the string expression are ignored.

Example 6-83 QUOTE$ function

  do
    clear
    print at 1,1: 
    message 'Enter a line of text to be quoted' 
    print 'Text:' 
    input '', length 30: line$ 
    if  _back or _exit  then exit do
    if  line$ = ''  then repeat do
    print 
    print 'Quoted text using the QUOTE$ function...' 
    print quote$(line$) 
    delay
  loop
  end
 
 
Text: 
? The little boy cried "wolf!" 
        
Quoted text using the QUOTE$ function... 
"The little boy cried ""wolf!""" 

6.4.30 REPEAT$(str_expr, int_expr)

REPEAT$ creates a string composed of the specified string repeated the specified number of times.

Example 6-84 REPEAT$ function

  print repeat$('Hi!', 9) 
  
  
Hi!Hi!Hi!Hi!Hi!Hi!Hi!Hi!Hi! 

6.4.31 REPLACE$(str_expr1, str_expr2 [,str_sep1][,str_sep2])

REPLACE$ searches for a list of patterns in the str_expr1 and replaces it with the output string from str_expr2. REPLACE$ returns the replaced string expression.

str_expr1 is a list of patterns to search for.

str_expr2 is the replacement list.

str_sep1 is the optional separator for replacement items. The default is a comma.

str_sep2 is the optional separator between the input and output text in items. Default is =.

Example 6-85 REPLACE$ function

  text$ = '01-Mar-1989' 
  print replace$(text$, 'r=y 8=9' , ' ') 
  end
 
 
01-May-1999 

6.4.32 RIGHT[$](str_expr, int_expr)

RIGHT$ returns the rightmost characters from a string. int_exp is the character position of the last character to be included in the substring COUNTING FROM THE RIGHT.

Example 6-86 RIGHT [$] function

  ans$ = right$('Daniel', 2) 
  print 'rightmost characters = '; ans$ 
  end
 
 
rightmost characters = el 

6.4.33 RPAD$(text_str, size[,pad_str])

RPAD$ pads a string on the right with pad characters. The default pad character is a space.

Example 6-87 RPAD$ function

  print rpad$('123', 6, '0') 
  end
 
 
123000 

6.4.34 RTRIM$(str_expr)

RTRIM$ returns a string without any trailing spaces (those on the right side).

Example 6-88 RTRIM$ function

  let a$ = '    HELLO    ' 
  print '*'; a$; '*' 
  let stripped$ = rtrim$(a$) 
  print '*'; stripped$; '*' 
  
  
*    HELLO    * 
*    HELLO* 

6.4.35 SEG$(str_expr, int_expr1, int_expr2)

The SEG$ function uses a first and last character position to extract the substring.

Example 6-89 SEG$ function

  print seg$('abcdefghijklmnop', 3, 8) 
  
  
cdefgh 

6.4.36 SORT$(str_expr1 [,str_expr2])

This function sorts the elements from a str_expr1 in ASCII value order; returns a list of the sorted elements.

str_expr1 contains the list of elements to be sorted.

str_expr2 is an optional separator. Default is a comma.

Example 6-90 SORT$ function

  a$ = 'code area is' 
  a_sort$ = sort$(a$, ' ') 
  print a_sort$ 
  end
 
 
area code is 

6.4.37 SPACE$(num_expr)

SPACE$ returns the number of spaces indicated by num_expr.

Example 6-91 SPACE$ function

  indent  = 10 
  indent$ = space$(10) 
  print indent$; 'This text is indented'; indent; 'spaces.' 
  end
  
  
          This text is indented 10 spaces. 

6.4.38 STR$(num_expr)

STR$ changes a number to a numeric string. The string that is created does not have any extra leading or trailing spaces.

Example 6-92 STR$ function

  age = 22 
  me$ = "I am " + str$(age) + " years old." 
  print me$ 
  end
  
  
I am 22 years old. 

6.4.39 TAB(int_expr)

When used with the PRINT statement, the TAB function moves the cursor or print mechanism to the right to a specified column.

Example 6-93 TAB function

  print tab(20); 'Hello there!' 
  
  
                    Hello there! 

6.4.40 TRIM$(str_expr)

TRIM$ returns the string specified stripped of any leading or trailing spaces and tabs.

Example 6-94 TRIM$ function

  let a$ = '    HELLO    ' 
  print '*'; a$; '*' 
  let stripped$ = trim$(a$) 
  print '*'; stripped$; '*' 
 
 
*    HELLO    * 
*HELLO* 

6.4.41 UCASE$(str_expr)

UCASE returns a string expression with all letters in upper case. See also Section 6.4.15, LCASE$(str_expr).

Example 6-95 UCASE$ function

  print ucase$('are you enjoying this manual so far?') 
 
 
ARE YOU ENJOYING THIS MANUAL SO FAR? 


Previous Next Contents Index