| Previous | Contents | Index |
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-96 UNQUOTE$ function |
|---|
do
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
print 'Quotes removed using the UNQUOTE$ function...'
print unquote$(line$)
delay
loop
end
Text:
? "I will not take these 'things' for granted."
Quotes removed using the UNQUOTE$ function...
I will not take these 'things' for granted.
|
VAL returns the floating-point value of a numeric string.
| Example 6-97 VAL function |
|---|
text$ = "My age is 20" z0$ = element$(text$, 4, ' ') age = val(z0$) print 'In 10 years I will be'; age + 10 end In 10 years I will be 30 |
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-98 WRAP$ function |
|---|
input 'Type in a sentence' ; text$
text$ = wrap$(text$, 5, 15)
print text$
end
Type in a sentence? This is an example of the wrap$ function.
This is an
example of
the wrap$
function.
|
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-99 XLATE$ function |
|---|
a$ = charset$
a$[66:66] = 'x' // change the "A" to a lowercase "x"
print xlate$('DAN', a$)
end
DxN
|
The following are string searching and comparing functions that SheerPower performs:
The COMPARE function compares two strings and returns a numeric value ranging from 0 (no match) to 100 (an exact match).
| Example 6-100 COMPARE function |
|---|
options$ = 'LEFT,RIGHT,UP,DOWN'
best = 0
best$ = ''
input 'Enter an option': usr_opt$
for idx = 1 to elements(options$)
opt$ = element$(options$, idx)
score = compare(opt$, usr_opt$)
if score > best then
best = score
best$ = opt$
end if
next idx
select case best
case 0
print 'Unknown option: '; usr_opt$
case 100
print 'Option okay, it was: '; usr_opt$
case else
print 'Misspelled option: '; usr_opt$
print using 'Did you mean ? (## percent)': best$, best
end select
end
Enter an option? dwn
Misspelled option: dwn
Did you mean DOWN (92 percent)
|
The ITEM function returns the number of the first item that matches the whole or partial item name given. A negative number is returned if more than one item matches.
Quoted data is treated as one element; the quotes are not removed.
| Example 6-101 ITEM function |
|---|
z = item('ADD,EXIT,EXTRACT,MODIFY', 'MOD')
print z
end
4
|
| Example 6-102 ITEM function |
|---|
z = item('ADD,EXIT,EXTRACT,MODIFY', 'EX')
print z
end
-2
|
str_expr1 contains a list of elements separated by commas. str_expr2 contains a string. MATCH compares str_expr2 with each of the elements in str_expr1 and gives the number of the element that matches.
The TRUE parameter is used if the match is to be case-exact. The default is case-insensitive.
| Example 6-103 MATCH function |
|---|
a$ = 'BLUE'
b$ = 'Blue'
c$ = a$
do
x = match('Red,White,Blue', c$, true)
print c$;
if x > 0 then
print ' is a match.'
else
print ' is not a match.'
c$ = b$
repeat do
end if
end do
end
BLUE is not a match.
Blue is a match.
|
This function matches any characters in text (str_expr1) with the pattern (str_expr2). str_expr1 is the text to search and str_expr2 is the pattern being searched for. It returns the location of the first character in the text that contains the pattern. If the characters cannot be found, it returns zero.
PATTERN Options and Examples
Pattern options can be mixed and matched with unlimited complexity.
The "?" matches any character in the text.
| Example 6-104 PATTERN function - ? |
|---|
if pattern('The quick brown fox', &
'f?x') > 0 then
print 'Found'
end if
end
Found
|
The "*" matches one or more of a character that precedes the single
asterisk (*).
It matches zero or more of a character that precedes the double
asterisk (**).
| Example 6-105 PATTERN function -* |
|---|
if pattern('aaa 01/26/99', 'a* *01/26/99') > 0 then
print 'The date is found'
end if
end
The date is found
|
The {} is used to define a group of characters. The characters in the enclosed group can be ranges such as {a-z} or individual characters such as {AQX}.
| Example 6-106 PATTERN function - { } |
|---|
text$ = 'A1N5V7N0'
rule_str$ = '{A-Z}{0-9}{A-Z}{0-9}{A-Z}{0-9}{A-Z}{0-9}'
if pattern(text$, rule_str$) > 0 then
print "Driver's license is correct."
end if
end
Driver's license is correct
|
The {^} looks for characters that are NOT {^A-Z}. The result below shows the difference between using '?' and {^}.
| Example 6-107 PATTERN function - {^ } |
|---|
print pattern('Mary J. Smith','{^Mar}')
print pattern('Mary J. Smith','J. {^S}')
print pattern('Mary J. Smith','J. S?')
end
4
0
6
|
The '~' (quote) character looks for a pattern of text that IS an * (stands for itself).
| Example 6-108 PATTERN function - ~ |
|---|
text$ = '$4,670.00'
if pattern(text$, '$~4,670.00') > 0 then
print 'Your text is correct.'
end if
end
Your text is correct.
|
This feature lets you designate binary data for detecting patterns that are not printable text characters. The characters in the enclosed group can be individual byte values such as {|13|} or groups such as {|0,13,200|}. Since {A-Z} is the range of A through Z, the proper syntax for this same range using byte values would be {{|65|}-{|90|}}.
| Example 6-109 PATTERN function - { |nnn,nnn,nnn | } |
|---|
text$ = 'Help yourself to some ' + chr$(13) + 'food'
if pattern(text$, '{|13|}') > 0 then
print 'Carriage return found.'
end if
end
Carriage return found.
|
The {<cc|ccc|c>} looks for text in str_expr1 that matches the enclosed groups.
| Example 6-110 PATTERN function - { <cc |ccc |c > } |
|---|
text$ = 'The area code is 619'
if pattern(text$, 'is {<619|714|916>}') > 0 then
print 'Your area code is on the list.'
end if
end
Your area code is on the list.
|
| Previous | Next | Contents | Index |