SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index

6.4.14 HASH$(str_expr1 [, str_expr2 [, int_expr]])

The HASH$ function changes the plain text in str_expr1 into a hashed eight-byte string value. It can be used to develop one-way hashed passwords. The optional text in str_expr2 and optional int_expr can be used to further make the hashed value unique.

Example 6-69 HASH$ function

  password$ = hash$('TRUTH') 
  input 'Password': pwd$ 
  if  hash$(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. 

6.4.15 LCASE$(str_expr)

LCASE returns a string expression with all letters in lower case. See Section 6.4.41, UCASE$(str_expr).

Example 6-70 LCASE$ function

  print lcase$('IT HAS BEEN A WONDERFUL DAY!') 
 
 
it has been a wonderful day! 

6.4.16 LEFT[$](str_expr, int_expr)

LEFT$ returns the leftmost nn characters from a string. int_expr is the last character position to be included in the resulting string.

Example 6-71 LEFT [$] function

  print left$('Hello there!', 3 ) 
  
  
Hel 

6.4.17 LEN(str_expr)

LEN returns the length of a string. It returns an integer.

Example 6-72 LEN function

  print len('These are the built-in functions of SheerPower.') 
  
  
47 

6.4.18 LPAD$(text_str, size [, pad_str])

LPAD$ pads a string on the left with pad characters. The default pad character is a space.

Example 6-73 LPAD$ function

  print lpad$('123', 6, '0') 
 
 
000123 

6.4.19 LTRIM$(str_expr)

LTRIM$ removes all leading spaces (those on the left side of the string).

Example 6-74 LTRIM$ function

  print ltrim$('   This function gets rid of leading spaces to the left of a string.') 
  end
 
 
This function gets rid of leading spaces to the left of a string. 

6.4.20 MAXLEN(str_var)

MAXLEN returns the maximum number of characters that a string variable can contain. Since all string variables are variable length with a maximum of 16711425, this function always returns 16711425.

Example 6-75 MAXLEN function

  print maxlen('Hi') 
  
  
16711425 

6.4.21 MEM(int_memory_address)

MEM() returns a zero-terminated string where the first byte starts at the given memory address.

If the memory address passed to the MEM() function is not readable, MEM() returns a zero-length string.

The format for MEM() is:


  string_result = mem(int_memory_address) 

Where STRING_RESULT is the zero-terminated string pointed to by the given memory address.

Example 6-76 MEM function

  library 'msvcrt.dll' 
  call 'ctime' (0%)         // returns a pointer to a zero-terminated string 
  mytime$ = mem(_integer)   // get the string with the MEM() fuction 
  print '-- '; mytime$ 
  end
 
 
 
-- Wed Dec 31 16:00:00 1969 

6.4.22 MID[$](str_expr, int_expr1 [,int_expr2])

MID$ or MID returns a substring from the middle characters of a specified string, leaving the string unchanged. int_expr1 is the starting position of the substring, and int_expr2 is the length of the substring. MID$(str_expr,int_expr1) will return the rest of the string.

Example 6-77 MID [$] function

  a$      = 'beginmiddleend' 
  middle$ = mid$(a$, 6, 6) 
  end$    = mid$(a$, 6) 
  print middle$, end$ 
  end
 
 
middle     middleend 

6.4.23 ORD(str_expr)

Given the ASCII name of a character, the ORD function returns the location of that character in the ASCII character table. It returns an integer number.

Example 6-78 ORD function

  print ord('H') 
  
  
72 

6.4.24 ORDNAME$(int_expr)

Given the location of a character in the ASCII character table, the ORDNAME$ function returns the name of that character.

Example 6-79 ORDNAME$ function

  print ordname$(69) 
  
  
E 

6.4.25 PARSE$(str_expr)

PARSE$ splits a string into tokens and returns each token separated by a space. Letters are UPPERCASE except within quotes. Tail comments are ignored. Embedded "$" characters are allowed. Names/words can start with digits. The maximum line length is 1024 characters.

Example 6-80 PARSE$ function

  a$ = 'company$ = 123abc$ + "and sons" !rnn' 
  print parse$(a$) 
  end
 
 
COMPANY$ = 123ABC$ + "and sons" 

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!""" 


Previous Next Contents Index