UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software UniBasic Commands Reference - Rocket Software

rocketsoftware.com
from rocketsoftware.com More from this publisher
11.04.2013 Views

MATCH Syntax var MATCH "[~] len [X, A, N] [text]" Synonym MATCHES Description The UniBasic MATCH or MATCHES function determines if a variable matches a specific pattern of characters, numbers, or a literal string. If var matches the pattern, MATCH or MATCHES returns 1. If var does not match the pattern, MATCH or MATCHES returns 0. Tip: You can mix codes and literal strings. To differentiate between the two, enclose the literal in single quotation marks within the larger pattern, which is enclosed in double quotation marks. Parameters The following table describes each parameter of the syntax. Parameter Description 1-442 UniBasic Commands Reference var Specifies the variable to compare with the MATCH expression. ~ Reverses the pattern. To match 4N, a string must contain four numeric characters. To match ~4N, a string must contain four characters that are not all numeric. len Specifies the number of characters to match. X Specifies that characters can be of any type. MATCH Parameters

Parameter Description A Specifies that only alphabetic characters match the pattern. N Specifies that only numbers match the pattern. text Specifies a literal string to search for. Enclose this literal text within single quotation marks if combined with a pattern (made up of X, A, and N). Examples MATCH Parameters (continued) In the following example, the program segment determines if the variable SSN is a valid social security number: SSN = "522-13-5124" SSNTEST = SSN MATCH "3N'-'2N'-'4N" The following program accepts as input a pattern to match and a string to search: PRINT "This program tests the MATCH function" PRINT "Enter pattern ": INPUT pattern PRINT "Enter string to match": INPUT string1 answer = string1 MATCH pattern PRINT \"\ : answer : \"\ In the following test executions of the preceding program, the user tests for a string that consists of three alphabetic characters followed by the literal “3A”. The literal (3A) is enclosed in quotation marks to differentiate it from the pattern 3A. :RUN BP match.test This program tests the MATCH function Enter pattern ?3A'3A' Enter string to match?AAA3A "1" :RUN BP match.test This program tests the MATCH function Enter pattern ?3A'3A' Enter string to match?3AAAA "0" MATCH 1-443

MATCH<br />

Syntax<br />

var MATCH "[~] len [X, A, N] [text]"<br />

Synonym<br />

MATCHES<br />

Description<br />

The <strong>UniBasic</strong> MATCH or MATCHES function determines if a variable matches a<br />

specific pattern of characters, numbers, or a literal string. If var matches the pattern,<br />

MATCH or MATCHES returns 1. If var does not match the pattern, MATCH or<br />

MATCHES returns 0.<br />

Tip: You can mix codes and literal strings. To differentiate between the two, enclose<br />

the literal in single quotation marks within the larger pattern, which is enclosed in<br />

double quotation marks.<br />

Parameters<br />

The following table describes each parameter of the syntax.<br />

Parameter Description<br />

1-442 <strong>UniBasic</strong> <strong>Commands</strong> <strong>Reference</strong><br />

var Specifies the variable to compare with the MATCH expression.<br />

~ Reverses the pattern. To match 4N, a string must contain four numeric<br />

characters. To match ~4N, a string must contain four characters that are not<br />

all numeric.<br />

len Specifies the number of characters to match.<br />

X Specifies that characters can be of any type.<br />

MATCH Parameters

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!