Sheerpower®
A Guide to the Sheerpower Language


Previous Contents Index

6.4.33 PHASH$(str_expr [, int_expr])

The str_expr is the text to be hashed, and the optional int_expr can be used to further randomize the hashing, resulting in a "salted hashed password."

The PHASH$() function returns a 24 byte string that is URL-SAFE. It can be used in a URL without having to urlencode$() it first.

The 24 character hash is extremely unique given any text string to hash.

The PHASH$ function can process over 5GB of text per second, making it suitable for very large data sets.

PHASH$() uses a different hashing method than HASH$() and is recommended over the use of the HASH$() function because it produces a more random hash and is faster. For more on HASH$() see Section 6.4.18, HASH$(str_expr1 [, str_expr2 [, int_expr] [,3]]).

Example 6-95 PHASH$ Function

  password$ = phash$('TRUTH') 
  input 'Password': pwd$ 
  if  phash$(pwd$) = password$  then
    print 'That was the correct password.' 
  else        
    print 'That was not the correct password.' 
  end if
  end     
 
 
password?  MONEY 
That was not the correct password. 

Example 6-96 PHASH$ Function With Salt

  password$ = phash$('TRUTH', 23993) 
  print password$ 
  end
  
fbOdJCu87od9s50kK7zuh32W  

6.4.34 PIECES(str_expr1 [,str_expr2])

and

6.4.35 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-97 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.36 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-98 PRETTY$ Function

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

6.4.37 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-99 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.38 REPEAT$(str_expr, int_expr)

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

Example 6-100 REPEAT$ Function

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

6.4.39 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-101 REPLACE$ Function

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

6.4.40 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-102 RIGHT [$] Function

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

6.4.41 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-103 RPAD$ Function

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

6.4.42 RTFENCODE$(str_expr)

The RTFENCODE$ function is used to write out text to an existing .RTF file while ensuring that the content of the text does not mess up the existing RTF code. To decode an RTF encoded string, see Section 6.4.43, RTFDECODE$(str_expr).

Example 6-104 RTFENCODE$ Function

  print rtfencode$('{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}' + 
    '{\colortbl;\red0\green0\blue0;\red255\green0\blue0;}' + 
    'tx720\tx1440\tx2880\tx5760' + 
    'This line is the default color\line' + 
    '\tab this line has 1 tab\line' + 
    '\tab\tab this line has 2 tabs\line' + 
    '\tab\tab\tab this line has 3 tabs\line' + 
    '\tab\tab\tab\tab this line has 4 tabs\line' + 
    '\cf2' + 
    '\tab This line is red and has a tab before it\line' + 
    '\cf1' + 
    '\page This line is the default color and the first line on page 2' + 
    '}') 
  end
 
\'7B\'5Crtf1\'5Cansi\'5Cdeff0 \'7B\'5Cfonttbl \'7B\'5Cf0 Courier;\'7D\'7D\'7B\'5 
Ccolortbl;\'5Cred0\'5Cgreen0\'5Cblue0;\'5Cred255\'5Cgreen0\'5Cblue0;\'7Dtx720\'5 
Ctx1440\'5Ctx2880\'5Ctx5760This line is the default color\'5Cline\'5Ctab this li 
ne has 1 tab\'5Cline\'5Ctab\'5Ctab this line has 2 tabs\'5Cline\'5Ctab\'5Ctab\'5 
Ctab this line has 3 tabs\'5Cline\'5Ctab\'5Ctab\'5Ctab\'5Ctab this line has 4 ta 
bs\'5Cline\'5Ccf2\'5Ctab This line is red and has a tab before it\'5Cline\'5Ccf1 
\'5Cpage This line is the default color and the first line on page 2\'7D 

6.4.43 RTFDECODE$(str_expr)

The RTFDECODE$ function is used to decode RTF encoded text. To encode text into RTF, see Section 6.4.42, RTFENCODE$(str_expr).

Example 6-105 RTFDECODE$ Function

  print rtfdecode$("\'7B\'5Crtf1\'5Cansi\'5Cdeff0 \'7B\'5Cfonttbl \'7B\'5Cf0 Courier;\'7D\'7D\'7B\'5") 
  end
 
{\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}{ 

6.4.44 RTRIM$(str_expr)

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

Example 6-106 RTRIM$ Function

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


Previous Next Contents Index