Sheerpower Logo
F.3  String Comparing and Searching

Sheerpower String Functions -- Optimized for Business Applications

Description:
Sheerpower includes many ways to search strings and compare them. Like all other string functions, they are highly optimized.

Importance in Business Applications:

  • CRM Systems:
    Accurate and quick matching of customer names, addresses, or other text-based data is essential for maintaining a seamless user experience. Optimized functions like COMPARE(), MATCH(), and POS() allow businesses to:
    • Swiftly identify and reconcile discrepancies in data entries.
    • Reduce the chances of errors in customer records.

  • Financial Applications:
    In financial systems, where transaction data needs to be processed rapidly, optimized string comparison functions help:
    • Reduce the time required to validate transactions against business rules.
    • Ensure smooth business operations without delays, leading to efficient processes and higher customer satisfaction.

  • Data Analytics:
    In data analytics, where vast amounts of text data might need to be processed, the efficiency of Sheerpower's string functions is critical:
    • Enable quicker and more complex text analysis, such as pattern recognition or data mining.
    • Lead to faster insights and more timely decision-making.
Summary: These highly optimized string functions in Sheerpower are essential for reliable, scalable, and efficient processing of text-based data, critical to many business operations.

String Comparing and Searching Functions

Description:
The COMPARE() function compares two strings and returns a numeric value ranging from 0 (no match) to 100 (an exact match).

Example:

options$ = 'LEFT,RIGHT,UP,DOWN' best = 0 best$ = '' input 'Enter an option', default 'DOWM': 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

Output: Did you mean DOWN (94 percent)

Description:
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.

Example:
z = item('ADD,EXIT,EXTRACT,MODIFY', 'MOD')
Output: 4
z = item('ADD,EXIT,EXTRACT,MODIFY', 'EX')
Output: -2

Description:
The MATCH() function compares str_expr2 with each of the elements in str_expr1 and returns 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:
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
Output: Blue is a match.

Description:
The PATTERN() function matches characters in str_expr1 against a pattern specified by str_expr2. It returns the position of the first character in str_expr1 that matches the pattern. If no match is found, it returns zero.

Pattern Options:

  • ? - Matches any single character. Example:
    if pattern('The quick brown fox', 'f?x') > 0 then print 'Found' end if
    Output: Found
  • * - Matches one or more of the preceding character, or zero or more with double asterisks. Example:
    if pattern('aaa 01/26/99', 'a* *01/26/99') > 0 then print 'The date is found' end if
    Output: The date is found
  • {} - Defines a group of characters. Can include ranges (e.g., {a-z}) or individual characters. Example:
    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
    Output: Driver's license is correct
  • {^} - Matches characters that are NOT in the specified set. Example:
    print pattern('Mary J. Smith', '{^Mar}') print pattern('Mary J. Smith', 'J. {^S}') print pattern('Mary J. Smith', 'J. S?')
    Output: 4 0 6
  • ~ - Matches a character pattern that stands for itself. Example:
    text$ = '$4,670.00' if pattern(text$, '$~4,670.00') > 0 then print 'Your text is correct.' end if
    Output: Your text is correct
  • {|nnn,nnn,nnn|} - Matches binary data. Useful for detecting non-printable text characters. Example:
    text$ = 'Help yourself to some ' + chr$(13) + 'food' if pattern(text$, '{|13|}') > 0 then print 'Carriage return found.' end if
    Output: Carriage return found
  • {} - Matches text in str_expr1 against enclosed groups. Example:
    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
    Output: Your area code is on the list
  • {(word_text)} - Matches a word or phrase. Example:
    a$ = 'There are dogs and cats in the house.' b$ = 'Everyone would like to make big$bucks!' if pattern(a$, '{(cats)}') > 0 then print 'The word was found.' end if if pattern(b$, '{(big$bucks)}') > 0 then print 'The $ word was found.' end if
    Output: The word was found. The $ word was found.
  • {|directive|} - Directives can be used to modify the search behavior (e.g., case-insensitive, beginning or end of a line). Example:
    a$ = 'ElEpHaNtS have trunks' b$ = 'water goes splash' if pattern(a$, '{|bol|}{|nocase|}elephants') > 0 then print 'elephants was found.' end if if pattern(b$, 'splash{|eol|}') > 0 then print 'splash was found.' end if
    Output: elephants was found. splash was found.

Description:

The POS() function searches for a substring within a string and returns the position of the first character of the substring. If the substring is not found, the function returns zero.

Example:
If int_expr is provided and is positive, the search starts at the int_expr position from the left. If int_expr is negative, the search is performed from right to left, beginning at the -int_expr position.

text$ = "Hello and goodbye"
andpos = pos(text$, 'and')
if andpos > 0 then print 'AND found at position'; andpos
Output: AND found at position 7

Description:
For a detailed description, see: Regular Expression Text Search

Arguments:
text_str (required): The text to operate on.

expr_str: The regular expression search with.

Example:
print regexsearch('The rain in Spain', 'rain')
Output: 5

Description:
The SCAN() function scans str_expr1 for the characters in str_expr2 and returns the position at which str_expr2 begins. The characters in str_expr2 need not appear contiguously in str_expr1.

Example:
a$ = 'Cameron Whitehorn'
b$ = 'amr Wtor'
position = scan(a$, b$)
Output: 2

Description:
The SKIP() function returns the position of the character following the last skipped character.

Example:
a$ = '31415 hello'
z = skip(a$, '1234567890 ')
print mid(a$, z)
Output: hello

Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.
Wide screen