CompareInfo.IsPrefix Methode

Definitie

Bepaalt of een tekenreeks begint met een specifiek voorvoegsel.

Overloads

Name Description
IsPrefix(String, String)

Bepaalt of de opgegeven brontekenreeks begint met het opgegeven voorvoegsel.

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

Bepaalt of een alleen-lezen reeks tekens begint met een specifiek voorvoegsel.

IsPrefix(String, String, CompareOptions)

Bepaalt of de opgegeven brontekenreeks begint met het opgegeven voorvoegsel met behulp van de opgegeven CompareOptions waarde.

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

Bepaalt of een tekenreeks begint met een specifiek voorvoegsel.

IsPrefix(String, String)

Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs

Bepaalt of de opgegeven brontekenreeks begint met het opgegeven voorvoegsel.

public:
 virtual bool IsPrefix(System::String ^ source, System::String ^ prefix);
public:
 bool IsPrefix(System::String ^ source, System::String ^ prefix);
public virtual bool IsPrefix(string source, string prefix);
public bool IsPrefix(string source, string prefix);
abstract member IsPrefix : string * string -> bool
override this.IsPrefix : string * string -> bool
member this.IsPrefix : string * string -> bool
Public Overridable Function IsPrefix (source As String, prefix As String) As Boolean
Public Function IsPrefix (source As String, prefix As String) As Boolean

Parameters

source
String

De tekenreeks waarin moet worden gezocht.

prefix
String

De tekenreeks die moet worden vergeleken met het begin van source.

Retouren

trueals de lengte kleiner prefix is dan of gelijk is aan de lengte van source en source begint met prefix; anders . false

Uitzonderingen

source is null.

– of –

prefix is null.

Voorbeelden

In het volgende voorbeeld wordt bepaald of een tekenreeks het voor- of achtervoegsel van een andere tekenreeks is.

using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Defines the strings to compare.
      String myStr1 = "calle";
      String myStr2 = "llegar";
      String myXfix = "lle";

      // Uses the CompareInfo property of the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      // Determines whether myXfix is a prefix of "calle" and "llegar".
      Console.WriteLine( "IsPrefix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsPrefix( myStr1, myXfix ) );
      Console.WriteLine( "IsPrefix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsPrefix( myStr2, myXfix ) );

      // Determines whether myXfix is a suffix of "calle" and "llegar".
      Console.WriteLine( "IsSuffix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsSuffix( myStr1, myXfix ) );
      Console.WriteLine( "IsSuffix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsSuffix( myStr2, myXfix ) );
   }
}


/*
This code produces the following output.

IsPrefix( calle, lle ) : False
IsPrefix( llegar, lle ) : True
IsSuffix( calle, lle ) : True
IsSuffix( llegar, lle ) : False

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Defines the strings to compare.
      Dim myStr1 As [String] = "calle"
      Dim myStr2 As [String] = "llegar"
      Dim myXfix As [String] = "lle"

      ' Uses the CompareInfo property of the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      ' Determines whether myXfix is a prefix of "calle" and "llegar".
      Console.WriteLine("IsPrefix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsPrefix(myStr1, myXfix))
      Console.WriteLine("IsPrefix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsPrefix(myStr2, myXfix))

      ' Determines whether myXfix is a suffix of "calle" and "llegar".
      Console.WriteLine("IsSuffix( {0}, {1} ) : {2}", myStr1, myXfix, myComp.IsSuffix(myStr1, myXfix))
      Console.WriteLine("IsSuffix( {0}, {1} ) : {2}", myStr2, myXfix, myComp.IsSuffix(myStr2, myXfix))

   End Sub

End Class


'This code produces the following output.
'
'IsPrefix( calle, lle ) : False
'IsPrefix( llegar, lle ) : True
'IsSuffix( calle, lle ) : True
'IsSuffix( llegar, lle ) : False

Opmerkingen

Elke tekenreeks begint en eindigt met een lege subtekenreeks (""); Dus als prefix het een lege tekenreeks is, retourneert truedeze methode .

Note

Indien mogelijk moet u vergelijkingsmethoden voor tekenreeksen aanroepen die een parameter van het type CompareOptions hebben om het type vergelijking op te geven dat wordt verwacht. Als algemene regel gebruikt u taalkundige opties (met behulp van de huidige cultuur) om tekenreeksen te vergelijken die worden weergegeven in de gebruikersinterface en specificeert u CompareOptions.Ordinal of CompareOptions.OrdinalIgnoreCase voor beveiligingsvergelijkingen.

Zie ook

Van toepassing op

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions)

Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs

Bepaalt of een alleen-lezen reeks tekens begint met een specifiek voorvoegsel.

public bool IsPrefix(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, System.Globalization.CompareOptions options = System.Globalization.CompareOptions.None);
member this.IsPrefix : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions -> bool
Public Function IsPrefix (source As ReadOnlySpan(Of Char), prefix As ReadOnlySpan(Of Char), Optional options As CompareOptions = System.Globalization.CompareOptions.None) As Boolean

Parameters

source
ReadOnlySpan<Char>

De alleen-lezen reeks tekens waarbinnen moet worden gezocht.

prefix
ReadOnlySpan<Char>

Het voorvoegsel dat moet worden vergeleken aan het begin van source.

options
CompareOptions

Een optionele combinatie van CompareOptions opsommingswaarden die tijdens de overeenkomst moeten worden gebruikt. De standaardwaarde is None.

Retouren

trueindien prefix aan het begin van source; anders . false

Uitzonderingen

options bevat een niet-ondersteunde combinatie van vlaggen.

Van toepassing op

IsPrefix(String, String, CompareOptions)

Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs

Bepaalt of de opgegeven brontekenreeks begint met het opgegeven voorvoegsel met behulp van de opgegeven CompareOptions waarde.

public:
 virtual bool IsPrefix(System::String ^ source, System::String ^ prefix, System::Globalization::CompareOptions options);
public:
 bool IsPrefix(System::String ^ source, System::String ^ prefix, System::Globalization::CompareOptions options);
public virtual bool IsPrefix(string source, string prefix, System.Globalization.CompareOptions options);
public bool IsPrefix(string source, string prefix, System.Globalization.CompareOptions options);
abstract member IsPrefix : string * string * System.Globalization.CompareOptions -> bool
override this.IsPrefix : string * string * System.Globalization.CompareOptions -> bool
member this.IsPrefix : string * string * System.Globalization.CompareOptions -> bool
Public Overridable Function IsPrefix (source As String, prefix As String, options As CompareOptions) As Boolean
Public Function IsPrefix (source As String, prefix As String, options As CompareOptions) As Boolean

Parameters

source
String

De tekenreeks waarin moet worden gezocht.

prefix
String

De tekenreeks die moet worden vergeleken met het begin van source.

options
CompareOptions

Een waarde die definieert hoe source en prefix moet worden vergeleken. options is de opsommingswaarde Ordinalof een bitsgewijze combinatie van een of meer van de volgende waarden: IgnoreCase, IgnoreSymbols, IgnoreNonSpace, , IgnoreWidthen IgnoreKanaType.

Retouren

trueals de lengte kleiner prefix is dan of gelijk is aan de lengte van source en source begint met prefix; anders . false

Uitzonderingen

source is null.

– of –

prefix is null.

options bevat een ongeldige CompareOptions waarde.

Voorbeelden

In het volgende voorbeeld wordt bepaald of een tekenreeks het voor- of achtervoegsel van een andere tekenreeks is met behulp van CompareOptions.

using System;
using System.Globalization;

public class SamplesCompareInfo  {

   public static void Main()  {

      // Defines the strings to compare.
      String myStr1 = "calle";
      String myStr2 = "llegar";
      String myXfix = "LLE";

      // Uses the CompareInfo property of the InvariantCulture.
      CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

      Console.WriteLine( "IsSuffix \"{0}\", \"{1}\"", myStr1, myXfix );
      Console.WriteLine( "   With no CompareOptions            : {0}", myComp.IsSuffix( myStr1, myXfix ) );
      Console.WriteLine( "   With None                         : {0}", myComp.IsSuffix( myStr1, myXfix, CompareOptions.None ) );
      Console.WriteLine( "   With Ordinal                      : {0}", myComp.IsSuffix( myStr1, myXfix, CompareOptions.Ordinal ) );
      Console.WriteLine( "   With IgnoreCase                   : {0}", myComp.IsSuffix( myStr1, myXfix, CompareOptions.IgnoreCase ) );

      Console.WriteLine( "IsPrefix \"{0}\", \"{1}\"", myStr2, myXfix );
      Console.WriteLine( "   With no CompareOptions            : {0}", myComp.IsPrefix( myStr2, myXfix ) );
      Console.WriteLine( "   With None                         : {0}", myComp.IsPrefix( myStr2, myXfix, CompareOptions.None ) );
      Console.WriteLine( "   With Ordinal                      : {0}", myComp.IsPrefix( myStr2, myXfix, CompareOptions.Ordinal ) );
      Console.WriteLine( "   With IgnoreCase                   : {0}", myComp.IsPrefix( myStr2, myXfix, CompareOptions.IgnoreCase ) );
   }
}


/*
This code produces the following output.

IsSuffix "calle", "LLE"
   With no CompareOptions            : False
   With None                         : False
   With Ordinal                      : False
   With IgnoreCase                   : True
IsPrefix "llegar", "LLE"
   With no CompareOptions            : False
   With None                         : False
   With Ordinal                      : False
   With IgnoreCase                   : True

*/
Imports System.Globalization

Public Class SamplesCompareInfo

   Public Shared Sub Main()

      ' Defines the strings to compare.
      Dim myStr1 As [String] = "calle"
      Dim myStr2 As [String] = "llegar"
      Dim myXfix As [String] = "LLE"

      ' Uses the CompareInfo property of the InvariantCulture.
      Dim myComp As CompareInfo = CultureInfo.InvariantCulture.CompareInfo

      Console.WriteLine("IsSuffix ""{0}"", ""{1}""", myStr1, myXfix)
      Console.WriteLine("   With no CompareOptions            : {0}", myComp.IsSuffix(myStr1, myXfix))
      Console.WriteLine("   With None                         : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.None))
      Console.WriteLine("   With Ordinal                      : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.Ordinal))
      Console.WriteLine("   With IgnoreCase                   : {0}", myComp.IsSuffix(myStr1, myXfix, CompareOptions.IgnoreCase))

      Console.WriteLine("IsPrefix ""{0}"", ""{1}""", myStr2, myXfix)
      Console.WriteLine("   With no CompareOptions            : {0}", myComp.IsPrefix(myStr2, myXfix))
      Console.WriteLine("   With None                         : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.None))
      Console.WriteLine("   With Ordinal                      : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.Ordinal))
      Console.WriteLine("   With IgnoreCase                   : {0}", myComp.IsPrefix(myStr2, myXfix, CompareOptions.IgnoreCase))

   End Sub

End Class


'This code produces the following output.
'
'IsSuffix "calle", "LLE"
'   With no CompareOptions            : False
'   With None                         : False
'   With Ordinal                      : False
'   With IgnoreCase                   : True
'IsPrefix "llegar", "LLE"
'   With no CompareOptions            : False
'   With None                         : False
'   With Ordinal                      : False
'   With IgnoreCase                   : True

Opmerkingen

Elke tekenreeks begint en eindigt met een lege subtekenreeks (""); Dus als prefix het een lege tekenreeks is, retourneert truedeze methode .

De CompareOptions.NumericOrdering waarden en CompareOptions.StringSort waarden zijn niet geldig voor deze methode.

Note

Indien mogelijk moet u vergelijkingsmethoden voor tekenreeksen aanroepen die een parameter van het type CompareOptions hebben om het type vergelijking op te geven dat wordt verwacht. Als algemene regel gebruikt u taalkundige opties (met behulp van de huidige cultuur) om tekenreeksen te vergelijken die worden weergegeven in de gebruikersinterface en specificeert u CompareOptions.Ordinal of CompareOptions.OrdinalIgnoreCase voor beveiligingsvergelijkingen.

Zie ook

Van toepassing op

IsPrefix(ReadOnlySpan<Char>, ReadOnlySpan<Char>, CompareOptions, Int32)

Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs
Bron:
CompareInfo.cs

Bepaalt of een tekenreeks begint met een specifiek voorvoegsel.

public:
 bool IsPrefix(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, System::Globalization::CompareOptions options, [Runtime::InteropServices::Out] int % matchLength);
public bool IsPrefix(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, System.Globalization.CompareOptions options, out int matchLength);
member this.IsPrefix : ReadOnlySpan<char> * ReadOnlySpan<char> * System.Globalization.CompareOptions * int -> bool
Public Function IsPrefix (source As ReadOnlySpan(Of Char), prefix As ReadOnlySpan(Of Char), options As CompareOptions, ByRef matchLength As Integer) As Boolean

Parameters

source
ReadOnlySpan<Char>

De alleen-lezen reeks tekens waarbinnen moet worden gezocht.

prefix
ReadOnlySpan<Char>

De alleen-lezen reeks tekens die het voorvoegsel bevatten om aan het begin van source.

options
CompareOptions

De CompareOptions te gebruiken tijdens de overeenkomst.

matchLength
Int32

Wanneer deze methode wordt geretourneerd, bevat het aantal tekens dat source overeenkomt met het gewenste voorvoegsel. Dit kan anders zijn dan de lengte van prefix als een taalkundige vergelijking wordt uitgevoerd. Ingesteld op 0 als het voorvoegsel niet overeenkomt.

Retouren

trueindien prefix aan het begin van source; anders . false

Uitzonderingen

options bevat een niet-ondersteunde combinatie van vlaggen.

Opmerkingen

Deze methode heeft meer overhead dan andere IsPrefix(String, String, CompareOptions) overbelastingen die geen argument aannemen matchLength . Roep deze overbelasting alleen aan als u de lengtegegevens van de overeenkomst nodig hebt.

Van toepassing op