DADiSP Worksheet Functions > Function Categories > String Manipulation > STRCMP

 

STRCMP

Purpose:

Compares two strings.

Syntax:

STRCMP("string1","string2", caseflag)

 

"string1"

-

A string.

"string2"

-

A string.

caseflag

-

Optional. An integer, the case sensitivity flag.

 

 

0:

case not significant (default)

1:

case significant

Returns:

An integer. Returns a negative number if string1 is less than string2 , 0 if they are the same, and a positive number if string1 is greater than string2.

Example:

strcmp("test", "test1")

 

performs a case independent comparison and returns -1 (a negative number) signifying the first string is less than the second.

Example:

strcmp("Hello","hello")

 

performs a case independent comparison and returns 0 indicating that the two strings are the same.

Example:

strcmp("Hello", "hello", 1)

 

performs a case dependent comparison and returns -1 (a negative number) signifying the first string is less than the second.

Remarks:

Non-alphabetic characters are assigned lexicographic positions based on their ASCII codes.

 

When a non-zero number is returned, the exact number that is returned is the difference in ASCII codes between the characters in the first position that are different.

 

Leading and trailing blanks are significant. Case is not significant if the optional case sensitivity flag is unspecified or 0. If the case sensitivity flag is nonzero, a case-sensitive comparison is performed.

 

The == operator performs a case dependent comparison that returns either 1 or 0. For example:

 

"Hello" == "hello"

 

returns 0.

See Also:

STREXTRACT

STRFIND

STRGET

STRMATCH

STRREPLACE

STRSORT