CompareInfo.IsPrefix 메서드

정의

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

오버로드

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

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

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의 시작 영역과 비교할 문자열입니다.

반환

prefix의 길이가 source로 시작하는 sourceprefix의 길이보다 작거나 같으면 true이고, 그렇지 않으면 false입니다.

예외

source이(가) null인 경우

또는

prefix이(가) null인 경우

예제

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

using namespace System;
using namespace System::Globalization;
int 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 S"calle" and S"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 S"calle" and S"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

*/
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.OrdinalIgnoreCase 를 지정 CompareOptions.Ordinal 하려면 언어 옵션(현재 문화권 사용)을 사용합니다.

추가 정보

적용 대상

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

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입니다.

반환

source의 시작 부분에서 prefix가 발생하는 경우 true이고, 그러지 않으면 false입니다.

예외

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

적용 대상

IsPrefix(String, String, CompareOptions)

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

sourceprefix을 비교하는 방법을 정의하는 값입니다. options는 열거형 값 Ordinal이거나 IgnoreCase, IgnoreSymbols, IgnoreNonSpace, IgnoreWidthIgnoreKanaType 값 중 하나 이상의 비트 조합입니다.

반환

prefix의 길이가 source로 시작하는 sourceprefix의 길이보다 작거나 같으면 true이고, 그렇지 않으면 false입니다.

예외

source이(가) null인 경우

또는

prefix이(가) null인 경우

options에 잘못된 CompareOptions 값이 포함된 경우

예제

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

using namespace System;
using namespace System::Globalization;
int 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
*/
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.StringSort 메서드에 대해 값이 잘못되었습니다.

참고

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

추가 정보

적용 대상

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

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으로 설정합니다.

반환

source의 시작 부분에서 prefix가 발생하는 경우 true이고, 그러지 않으면 false입니다.

예외

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

설명

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

적용 대상