A Guide to the Sheerpower Language

Previous Contents Index

6.4.18 HASH$(str_expr1 [, str_expr2 [, int_expr] [,3]])

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 (also known as a "SALT integer").

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

Example 6-78 HASH$ Function

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

Example 6-79 HASH$ Function With Salt

  password$ = hash$('TRUTH', 'someText', 1456) 
  print password$ 

The optional "3" value implements a different type of hashing method called "Prime Hashing". The result is a 16 digit hex string that is very nice to use as a KEY into a table. If two str_expr1 return the same 16 digit hex hash, then those two strings are probably identical.

If the Prime Hashing method is used but with no salt integer, then a salt of "0" must be used. For example:

Example 6-80 Prime Hashing With No Salt Integer

  password$ = hash$('TRUTH', 'someText', 0, 3) 
  print password$ 

6.4.19 HTMLDECODE$(str_expr)

The HTMLDECODE$ function takes a hexidecimal HTML encoded string and decodes it into actual HTML code. In the example below, the "&#X3C;" and "&#X3E;" hexidecimal character references are are converted to the left angle bracket "<" and right angle bracket ">" symbols. To encode string data containing HTML tags, see Section 6.4.20, HTMLENCODE$(str_expr).

Example 6-81 HTMLDECODE$ Function

  print htmldecode$('This is an &#X3C;html&#X3E; tag') 
This is an <html> tag 

6.4.20 HTMLENCODE$(str_expr)

The HTMLENCODE$ function takes a string and returns an HTML encoded string that encodes symbols like "<" and ">" using hexadecimal character references. To decode an encoded string, see Section 6.4.19, HTMLDECODE$(str_expr).

Example 6-82 HTMLENCODE$ Function

  print htmlencode$('This is an <html> tag') 
This is an &#X3C;html&#X3E; tag 

6.4.21 LCASE$(str_expr)

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

Example 6-83 LCASE$ Function

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

6.4.22 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-84 LEFT [$] Function

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

6.4.23 LEN(str_expr)

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

Example 6-85 LEN Function

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

6.4.24 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-86 LPAD$ Function

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

6.4.25 LTRIM$(str_expr)

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

Example 6-87 LTRIM$ Function

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

6.4.26 MATCHWORD(str_expr1, str_expr2[, num_expr])

The MATCHWORD() function returns the character location of a given word specified in string_expr2, which can also be a phrase of words separated by spaces as well as a single word.

MATCHWORD() returns a zero if the word is not found in the list. The search is case-regardless. Words are made up of letters and/or numbers. After calling matchword(), _integer contains the word index# (3 in the example below).

There is an optional 3rd argument "num_expr" which is the text scan starting position. The default text scan starting position is 1. The MATCHWORD() function is very useful when searching for words or phrases.

Example 6-88 MATCHWORD Function

  print matchword('list   of    words  or 11111 numbers', 'Words') 
  print _integer 

6.4.27 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-89 MAXLEN Function

  print maxlen('Hi') 

6.4.28 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-90 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$ 
-- Wed Dec 31 16:00:00 1969 

6.4.29 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-91 MID [$] Function

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

6.4.30 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-92 ORD Function

  print ord('H') 

6.4.31 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-93 ORDNAME$ Function

  print ordname$(69) 

6.4.32 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-94 PARSE$ Function

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

Previous Next Contents Index