xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

WildMatch()

Tests if a string begins with a search pattern.

Syntax

WildMatch( <cPattern>, <cString>, [<lFullMatch>] ) --> lFound

Arguments

<cPattern>
This is a character string defining the search pattern. It may include as wild card characters the question mark (?, matches one character) or the asterisk (*, matches any number of characters).
<cString>
This parameter is a character string to match against <cPattern>.
<lFullMatch>
The parameter defaults to .F. (false), causing the function to return when a matching pattern is found at the beginning of <cString>. When .T. (true) is passed, <cString> is matched entirely against <cPattern>.

Return

The function returns .T. (true) when <cString> contains the search pattern.

Description

WildMatch() is a pattern matching function that searches a string for a search pattern. If the search pattern is found, the function returns .T. (true).

WildMatch() operates similarly to OrdWildSeek() but can be used as part of a SET FILTER condition on an unindexed database.

Info

See also:$, At(), IN, OrdWildSeek(), SET FILTER
Category: Character functions , xHarbour extensions
Source:rtl\strmatch.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the pattern matching algorithm employed
// by WildMatch() and how the function can be used as filter condition
// for a database

   PROCEDURE Main
      LOCAL cStr := "The xHarbour compiler"

      ? WildMatch( "bo?"  , cStr, .F. )  // result: .F.
      ? WildMatch( "bo?"  , cStr, .T. )  // result: .F.

      ? WildMatch( "*bo"  , cStr, .F. )  // result: .T.
      ? WildMatch( "*bo"  , cStr, .T. )  // result: .F.

      ? WildMatch( "The"  , cStr, .F. )  // result: .T.
      ? WildMatch( "The"  , cStr, .T. )  // result: .F.

      ? WildMatch( "The*r", cStr, .F. )  // result: .T.
      ? WildMatch( "The*r", cStr, .T. )  // result: .T.

      ? WildMatch( "The?x", cStr, .F. )  // result: .T.
      ? WildMatch( "The?x", cStr, .T. )  // result: .F.

      USE Customer
      SET FILTER TO WildMatch( "W*s", FIELD->LastName )

      GO TOP
      DbEval( {|| QOut( FIELD->LastName ) } )
      // Output: Names starting with "W" and ending with "s"
      // Walters
      // Waters

      CLOSE Customer
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe