S_MATCH

Match a string

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
xcall S_MATCH(match_string, field, result)

Arguments

match_string

The match control string. (a)

field

The field that S_MATCH will attempt to match. (a)

result

The variable that will be loaded with one of the following values: (n)

1 = The match is successful.

0 = The match is not successful.

Discussion

The S_MATCH subroutine performs a string match.

The match_string argument contains one or more match expressions, where a match expression is zero or more asterisks (*), followed by zero or more strings, quoted strings, or question marks (?). The following interpretations apply:

*

Match zero or more characters.

?

Match any single character.

“quoted string”

Match this string exactly.

unquoted string

Match this string, ignoring uppercase and lowercase.

For the field “This is a test string”, here are some examples of what matches and what doesn’t:

Match string

Result

“*test*”

1

“test”

0

“string”

0

“*string”

1

To specify a quote character within the match_string, use two consecutive quotation marks (““).

Note

S_MATCH is affected by the case value of the LOCALIZE routine wherever the operation depends on (or is independent of) the case of a character. It is also affected by the current operating system language locale.

Examples

The example below inputs a match control string, searches a file for that string, and displays the number of matches that were found.

.define TTCHN           ,1
.define NMCHN           ,2
record
    line                ,a80
    found               ,d1
    match_str           ,a80
    matches             ,d2
proc
    open(TTCHN, o, "tt:")
    open(NMCHN, i, "names.ddf")
    xcall flags(20, 1)
    display(TTCHN, "Enter a string to match: ")
    reads(TTCHN, match_str)
    repeat
      begin
        reads(NMCHN, line)  [eof=done]
        xcall s_match(match_str(1:%trim(match_str)),
  &           line(1:%trim(line)), found)
        if (found)
          begin
            incr matches
            writes(TTCHN, line)
          end
      end
done,
    display(TTCHN, %string(matches), " matches found.")
    close TTCHN
    close NMCHN
    stop
end

If names.ddf contains the following data and the match string is “B*”, three matches will be found:

Ben

,Jones

Beverly

,Jones

Burt

,Jones