次の方法で共有


IPatternMatcher.TryMatch(String) Method

Definition

Determines if, and how well a candidate string matches a search pattern and a set of PatternMatcherCreationOptions.

public:
 Nullable<Microsoft::VisualStudio::Text::PatternMatching::PatternMatch> TryMatch(System::String ^ candidate);
public Microsoft.VisualStudio.Text.PatternMatching.PatternMatch? TryMatch (string candidate);
abstract member TryMatch : string -> Nullable<Microsoft.VisualStudio.Text.PatternMatching.PatternMatch>
Public Function TryMatch (candidate As String) As Nullable(Of PatternMatch)

Parameters

candidate
String

The string to evaluate for relevancy.

Returns

A PatternMatch object describing how well the candidate matched the pattern. If no match is found, this returns null instead.

Remarks

This pattern matcher uses the concepts of a 'Pattern' and a 'Candidate' to to differentiate between what the user types to search and what the system compares against. The pattern and some PatternMatcherCreationOptions are specified in IPatternMatcherFactory in order to obtain an IPatternMatcher.

The user can then call this method repeatedly with multiple candidates to filter out non-matches, and obtain sortable PatternMatch objects to help decide what the user actually wanted.

A few examples are useful here. Suppose the user obtains an IPatternMatcher using the following: Pattern = "PatMat"

The following calls to TryMatch could expect these results: Candidate = "PatternMatcher" Returns a match containing CamelCaseExact.

Candidate = "IPatternMatcher" Returns a match containing CamelCaseSubstring

Candidate = "patmat" Returns a match containing Exact, but IsCaseSensitive will be false.

Candidate = "Not A Match" Returns null.

To determine sort order, call CompareTo(PatternMatch).

Applies to