Strings.StrComp(String, String, CompareMethod) 메서드

정의

문자열 비교의 결과에 따라 -1, 0 또는 1을 반환합니다.

public static int StrComp (string? String1, string? String2, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
public static int StrComp (string String1, string String2, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
static member StrComp : string * string * Microsoft.VisualBasic.CompareMethod -> int
Public Function StrComp (String1 As String, String2 As String, Optional Compare As CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary) As Integer

매개 변수

String1
String

필수 요소. 임의의 유효한 String 식입니다.

String2
String

필수 요소. 임의의 유효한 String 식입니다.

Compare
CompareMethod

선택 사항입니다. 문자열 비교의 형식을 지정합니다. Compare가 생략되면 Option Compare 설정에 따라 비교 형식이 결정됩니다.

반환

다음 값 중 하나입니다.

조건StrComp 함수의 반환 값
String1String2 앞에 정렬되는 경우-1
String1String2와 같습니다.0
String1String2 뒤에 정렬되는 경우1

예외

Compare 값이 잘못된 경우

예제

이 예제에서는 함수를 StrComp 사용하여 문자열 비교 결과를 반환합니다.

' Defines variables.
Dim testStr1 As String = "ABCD"
Dim testStr2 As String = "abcd"
Dim testComp As Integer
' The two strings sort equally. Returns 0.
testComp = StrComp(testStr1, testStr2, CompareMethod.Text)
' testStr1 sorts before testStr2. Returns -1.
testComp = StrComp(testStr1, testStr2, CompareMethod.Binary)
' testStr2 sorts after testStr1. Returns 1.
testComp = StrComp(testStr2, testStr1, CompareMethod.Binary)

설명

문자열은 첫 번째 문자로 시작하는 영숫자 정렬 값과 비교됩니다. 이진 비교, 텍스트 비교 및 정렬 순서에 대한 자세한 내용은 Option Compare 문을 참조하세요.

Compare 인수 설정은 다음과 같습니다.

상수 Description
Binary 문자의 내부 이진 표현에서 파생된 정렬 순서에 따라 이진 비교를 수행합니다.
Text 시스템 값에 따라 결정되는 대/소문자를 구분하지 않는 텍스트 정렬 순서에 따라 텍스트 비교를 LocaleID 수행합니다.

적용 대상

추가 정보