A Guide to the Sheerpower Language

Previous Contents Index

6.4.45 SEG$(str_expr, int_expr1, int_expr2)

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

Example 6-107 SEG$ Function

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

6.4.46 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-108 SORT$ Function

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

6.4.47 SPACE$(num_expr)

SPACE$ returns the number of spaces indicated by num_expr.

Example 6-109 SPACE$ Function

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

6.4.48 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-110 STR$ Function

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

6.4.49 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-111 TAB Function

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

6.4.50 TRIM$(str_expr)

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

Example 6-112 TRIM$ Function

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

6.4.51 UCASE$(str_expr)

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

Example 6-113 UCASE$ Function

  print ucase$('are you enjoying this manual so far?') 

6.4.52 UNQUOTE$(str_expr)

The UNQUOTE$ function removes one set of quotes from a quoted string expression. If the string expression is not quoted, UNQUOTE$ leaves the string alone. UNQUOTE$ does not affect internally quoted elements.

Example 6-114 UNQUOTE$ Function

    print at 1,1: 
    message 'Enter a line of text to be unquoted' 
    print 'Text:' 
    input '', length 50: line$ 
    if  _back or _exit  then exit do
    if  line$ = ''  then repeat do
    print 'Quotes removed using the UNQUOTE$ function...' 
    print unquote$(line$) 
? "I will not take these 'things' for granted." 
Quotes removed using the UNQUOTE$ function... 
I will not take these 'things' for granted. 

6.4.53 URLENCODE$(str_expr)

The URLENCODE$ function takes a string and converts it to a new string that can be used as data in a browser URL. Spaces in the string are converted to + signs, and in the example below, the ampersand & is converted to %26. To decode a converted string, see Section 6.4.54, URLDECODE$(str_expr).

Example 6-115 URLENCODE$ Function

  mydata$ = '?phrase=' + urlencode$('Dogs & cats') 
  print mydata$ 

6.4.54 URLDECODE$(str_expr)

The URLDECODE$ function takes the encoded string data in a browser URL and decodes it into plain text. In the example below, the + signs are converted to spaces, and the %26 is converted to an ampersand (&). To encode string data for use in a browser URL see Section 6.4.53, URLENCODE$(str_expr).

Example 6-116 URLDECODE$ Function

  print urldecode$('?phrase=Dogs+%26+cats ') 
?phrase=Dogs & cats 

6.4.55 UUID$

UUID$ can be called with either no parameters or a single parameter (the format). The default is format 0. The function always returns a "universally unique identifier", so is very useful when one wants to generate a unique key value for a table. In addition, the key values are SPARSE, so not easily guessable and not easily accidentally entered by a typo error.

Example 6-117 UUID$ Function

  print uuid$ 
  print uuid$(0)  // a base64-encoded UUID - this is the default if no parameters are given 
  print uuid$(1)  // a UUID in hex digits 
  print uuid$(2)  // a UUID in hex, with dashes between elements 
  print uuid$(3)  // a UUID in hex with dashes, enclosed with braces 
// sample results - the UUIDs generated are unique each time: 

Format values are:

0 32 hex digits made from the 128 bit uuid, but in memory byte order. One cannot attach any meaning to the order of the hex byte digits - this is very fast (over 3 million/sec). This is the default returned value if no parameter is given
1 32 hex digits as well but, in the order specified by the RFC - so one can attach meaning to the hex digits (about 900,000/sec)
2 32 hex digits as above, but grouped with four dashes (about 900,000/sec) - 36 characters in total
3 Same as above, but with additional { and } at the front and back - this is the standard display format for a UUID, 38 characters in total

Using a UUID eliminates handlers having to worry about key value collisions.

If one still wants to attach meaning to the key, one method would be to PREFIX the UUID with a value such as "client" for the client master table, etc.

Our default UUID format returns 22 bytes. We achieve this space savings by converting the 128-bit standard internal UUID into a base-64 encoded string, and then stripping off the trailing two "==" that the base-64 encoding generates. Then, to make it "URL safe", we change any generated "+" to "-" and "/" to "_".

UUIDs are also often also called GUIDs (Globally Unique Identifiers). For more information on UUIDs:

6.4.56 VAL(num_str)

VAL returns the floating-point value of a numeric string.

Example 6-118 VAL Function

  text$ = "My age is 20" 
  z0$   = element$(text$, 4, ' ') 
  age   = val(z0$) 
  print 'In 10 years I will be'; age + 10 
In 10 years I will be 30 

6.4.57 WRAP$(str_expr, int_expr1, int_expr2)

WRAP$ returns a word-wrapped text string, given left and right margins. Each line of the string is separated with a CR/LF.

Where string_expr = text string to wrap, int_expr1 = left margin, int_expr2 = right margin.

Example 6-119 WRAP$ Function

  input 'Type in a sentence' ; text$ 
  text$ = wrap$(text$, 5, 15) 
  print text$ 
Type in a sentence? This is an example of the wrap$ function. 
     This is an 
     example of 
     the wrap$ 

6.4.58 XLATE$(str_expr1, str_expr2)

The XLATE$ function translates one string to another by referencing a table you supply. For example, the XLATE$ function can translate from EBCDIC to ASCII. The first str_expr is the string to be translated. The second str_expr is the translation table.

Example 6-120 XLATE$ Function

  a$ = charset$
  a$[66:66] = 'x'  // change the "A" to a lowercase "x" 
  print xlate$('DAN', a$) 

Previous Next Contents Index