CompareInfo.IsPrefix 메서드

정의

문자열이 특정 접두사로 시작하는지 여부를 결정합니다.

오버로드

Name Description
IsPrefix(String, String)

지정된 소스 문자열이 지정된 접두사로 시작하는지 여부를 결정합니다.

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

읽기 전용 문자 범위가 특정 접두사로 시작하는지 여부를 결정합니다.

IsPrefix(String, String, CompareOptions)

지정된 값을 사용하여 CompareOptions 지정된 소스 문자열이 지정된 접두사로 시작하는지 여부를 결정합니다.

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

문자열이 특정 접두사로 시작하는지 여부를 결정합니다.

IsPrefix(String, String)

Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs

지정된 소스 문자열이 지정된 접두사로 시작하는지 여부를 결정합니다.

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

매개 변수

source
String

검색할 문자열입니다.

prefix
String

의 시작 부분과 비교할 문자열입니다 source.

반품

길이 가 길이보다 작거나 같으면 이고, 그렇지 않으면 시작합니다.

예외

sourcenull입니다.

-또는-

prefixnull입니다.

예제

다음 예제에서는 문자열이 다른 문자열의 접두사인지 접미사인지 확인합니다.

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

설명

모든 문자열은 빈 부분 문자열("")로 시작하고 끝납니다. 따라서 빈 문자열이면 prefix 이 메서드가 반환됩니다 true.

메모

가능하면 형식 CompareOptions 의 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.OrdinalCompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

추가 정보

적용 대상

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

Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs

읽기 전용 문자 범위가 특정 접두사로 시작하는지 여부를 결정합니다.

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

매개 변수

source
ReadOnlySpan<Char>

검색할 문자의 읽기 전용 범위입니다.

prefix
ReadOnlySpan<Char>

시작 시 일치를 시도할 접두사입니다 source.

options
CompareOptions

일치 중에 사용할 열거형 값의 CompareOptions 선택적 조합입니다. 기본값은 None입니다.

반품

가 시작되면 그렇지 않으면 .입니다.

예외

options 에는 지원되지 않는 플래그 조합이 포함되어 있습니다.

적용 대상

IsPrefix(String, String, CompareOptions)

Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs

지정된 값을 사용하여 CompareOptions 지정된 소스 문자열이 지정된 접두사로 시작하는지 여부를 결정합니다.

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

매개 변수

source
String

검색할 문자열입니다.

prefix
String

의 시작 부분과 비교할 문자열입니다 source.

options
CompareOptions

비교 방법 및 source 비교 방법을 prefix 정의하는 값입니다. options는 열거형 값이거나 다음 값 OrdinalIgnoreCaseIgnoreSymbolsIgnoreNonSpaceIgnoreWidthIgnoreKanaType중 하나 이상의 비트 조합입니다.

반품

길이 가 길이보다 작거나 같으면 이고, 그렇지 않으면 시작합니다.

예외

sourcenull입니다.

-또는-

prefixnull입니다.

options 에 잘못된 CompareOptions 값이 포함되어 있습니다.

예제

다음 예제에서는 문자열을 사용 하 여 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

설명

모든 문자열은 빈 부분 문자열("")로 시작하고 끝납니다. 따라서 빈 문자열이면 prefix 이 메서드가 반환됩니다 true.

이 메서드에는 CompareOptions.NumericOrdering 값과 CompareOptions.StringSort 값이 잘못되었습니다.

메모

가능하면 형식 CompareOptions 의 매개 변수가 있는 문자열 비교 메서드를 호출하여 예상되는 비교 종류를 지정해야 합니다. 일반적으로 사용자 인터페이스에 표시된 문자열을 비교하고 보안 비교를 위해 CompareOptions.OrdinalCompareOptions.OrdinalIgnoreCase 언어 옵션(현재 문화권 사용)을 사용합니다.

추가 정보

적용 대상

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

Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs
Source:
CompareInfo.cs

문자열이 특정 접두사로 시작하는지 여부를 결정합니다.

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

매개 변수

source
ReadOnlySpan<Char>

검색할 문자의 읽기 전용 범위입니다.

prefix
ReadOnlySpan<Char>

시작 시 일치를 시도할 접두사를 포함하는 문자의 읽기 전용 범위입니다 source.

options
CompareOptions

CompareOptions 일치 중에 사용할 항목입니다.

matchLength
Int32

이 메서드가 반환될 때 원하는 접두사와 일치하는 문자 source 수를 포함합니다. 이는 언어 비교가 수행되는 경우의 prefix 길이와 다를 수 있습니다. 접두사 일치 하지 않으면 0으로 설정 합니다.

반품

가 시작되면 그렇지 않으면 .입니다.

예외

options 에는 지원되지 않는 플래그 조합이 포함되어 있습니다.

설명

이 메서드는 인수를 사용하지 matchLength 않는 다른 IsPrefix(String, String, CompareOptions) 오버로드보다 오버헤드가 더 큽니다. 일치 길이 정보가 필요한 경우에만 이 오버로드를 호출합니다.

적용 대상