Share via


Tipo de dados de sequência de caracteres (Visual Basic)

Contém seqüências de 16 bits sem sinal de-(2 -byte) pontos de código que variam em valor de 0 a 65535. Cada o ponto de código, ou o código de caractere representa um único caractere Unicode . A string can contain from 0 to approximately two billion (2 ^ 31) Unicode characters.

Comentários

Use the String data type to hold multiple characters without the array management overhead of Char(), an array of Char elements.

The default value of String is Nothing (a null reference). Note that this is not the same as the empty string (value "").

Unicode Characters

Os primeiro 128 pontos de código (0–127) do Unicode correspondem às letras e símbolos de um padrão EUA teclado. Esses pontos de 128 código primeiro são as mesmas que ASCII, conjunto de caracteres define. The second 128 code points (128–255) represent special characters, such as Latin-based alphabet letters, accents, currency symbols, and fractions. Unicode uses the remaining code points (256-65535) for a wide variety of symbols. This includes worldwide textual characters, diacritics, and mathematical and technical symbols.

You can use methods such as IsDigit and IsPunctuation on an individual character in a String variable to determine its Unicode classification.

Format Requirements

You must enclose a String literal within quotation marks (" "). If you must include a quotation mark as one of the characters in the string, you use two contiguous quotation marks (""). The following example illustrates this.

Dim j As String = "Joe said ""Hello"" to me."
Dim h As String = "Hello"
' The following messages all display the same thing:
' "Joe said "Hello" to me."
MsgBox(j)
MsgBox("Joe said " & """" & h & """" & " to me.")
MsgBox("Joe said """ & h & """ to me.")

Note that the contiguous quotation marks that represent a quotation mark in the string are independent of the quotation marks that begin and end the String literal.

String Manipulations

Once you assign a string to a String variable, that string is immutable, which means you cannot change its length or contents. When you alter a string in any way, Visual Basic creates a new string and abandons the previous one. The String variable then points to the new string.

You can manipulate the contents of a String variable by using a variety of string functions. O exemplo a seguir ilustra o Left função

Dim S As String = "Database"
' The following statement sets S to a new string containing "Data".
S = Microsoft.VisualBasic.Left(S, 4)

A string created by another component might be padded with leading or trailing spaces. Se você receber uma seqüência de caracteres, você pode usar o Trim, LTrim, e RTrim funções para remover esses espaços.

For more information about string manipulations, see Sequências de caracteres em Visual Basic.

Programming Tips

  • Negative Numbers. Lembre-se de que os caracteres será mantido por String não estão assinadas e não pode representar valores negativos. In any case, you should not use String to hold numeric values.

  • Considerações de interoperabilidade. If you are interfacing with components not written for the .NET Framework, for example Automation or COM objects, remember that string characters have a different data width (8 bits) in other environments. If you are passing a string argument of 8-bit characters to such a component, declare it as Byte(), an array of Byte elements, instead of String in your new Visual Basic code.

  • Tipo Caracteres. Acrescentando o caractere de tipo de identificador $ para qualquer identificador de força para o String tipo de dados. Stringtem nenhum caractere de tipo literal. However, the compiler treats literals enclosed in quotation marks (" ") as String.

  • Framework Type. O tipo correspondente na.NET Framework é o System.String classe.

Consulte também

Tarefas

Como: otimizar o armazenamento de inteiros positivos com tipos sem-sinal (Visual Basic)

Como: Chamar uma função do Windows que obtém tipos sem-sinal (Visual Basic)

Referência

Resumo de tipo de dados (Visual Basic)

System.String

Caractere tipo de dados (Visual Basic)

Funções de conversão de tipo (Visual Basic)

Resumo de conversão (Visual Basic)

Conceitos

Uso eficiente de tipos de dados (Visual Basic)