Compartilhar via


Opção Comparar Declarações

Declares the default comparison method to use when comparing string data.

Option Compare { Binary | Text }

Parts

Term

Definition

Binary

Optional. Results in string comparisons based on a sort order derived from the internal binary representations of the characters.

Esse tipo de comparação é útil principalmente se as seqüências de caracteres podem conter caracteres que não devem ser interpretadas como texto. Nesse caso, você não deseja polarização comparações com Equivalências em ordem alfabética, como, por exemplo, não diferenciação de maiúsculas e minúsculas.

Text

Optional. Results in string comparisons based on a case-insensitive text sort order determined by your system's locale.

Esse tipo de comparação é útil se as seqüências de caracteres contém todos os caracteres de texto e deseja compará-los a levar em Equivalências alfabético de conta, como a não diferenciação de maiúsculas e minúsculas e letras intimamente relacionadas. For example, you might want to consider A and a to be equal, and Ä and ä to come before B and b.

Comentários

If used, the Option Compare statement must appear in a file before any other source code statements.

The Option Compare statement specifies the string comparison method (Binary or Text) for a class, module, or structure. If an Option Compare statement is not included, the default text comparison method is Binary.

In Microsoft Windows, sort order is determined by the code page. For more information, see Code Pages.

In the following example, characters in the English/European code page (ANSI 1252) are sorted by using Option Compare Binary, which produces a typical binary sort order.

A < B < E < Z < a < b < e < z < À < Ê < Ø < à < ê < ø

When the same characters in the same code page are sorted by using Option Compare Text, the following text sort order is produced.

(A=a) < (À = à) < (B=b) < (E=e) < (Ê = ê) < (Z=z) < (Ø = ø)

You can also set Option Compare in the Visual Studio integrated development environment (IDE) or on a command line.

ObservaçãoObservação

Seu computador pode mostrar nomes ou locais diferentes para alguns dos elementos da interface do usuário do Visual Studio nas instruções a seguir. A edição do Visual Studio que você possui e as configurações que você usa determinam esses elementos. Para obter mais informações, consulte Configurações do Visual Studio.

To set Option Compare in the IDE

  1. On the Tools menu, click Options.

  2. Open the Projects and Solutions node.

  3. Choose VB Defaults.

  4. Modify the Option Compare setting.

To set Option Compare on the command line

Exemplo

The following example uses the Option Compare statement to set the binary comparison as the default string comparison method.

' Set the string comparison method to Binary ("AAA" < "aaa").
Option Compare Binary

The following example uses the Option Compare statement to set the case-insensitive text sort order as the default string comparison method.

' Set the string comparison method to Text ("AAA" = "aaa").
Option Compare Text

Consulte também

Referência

Operadores de comparação (Visual Basic)

InStr

InStrRev

Replace

Split

StrComp

/optioncompare

Instrução Option Explicit (Visual Basic)

Opção declaração estrito

/optionexplicit

/optionstrict

Caixa de diálogo Opções de padrões, projetos, Visual Basic