Funzione Chr

Restituisce il carattere associato al codice carattere ANSI specificato.

Sintassi

Chr(charcode)

Note

L'argomento charcode è un numero che identifica un carattere. I numeri da 0 a 31 sono gli stessi dei codici di carattere ASCII standard non stampabili. Ad esempio, Chr(10) restituisce un carattere di avanzamento riga.

Nell'esempio seguente viene utilizzata la funzione Chr per restituire il carattere associato al codice carattere specificato.

Nell'esempio seguente viene illustrato l'uso della funzione Chr.

Esempio 1

Dim MyChar
MyChar = Chr(65)   ' Returns 'A'.
'Output: 'A’

Esempio 2

MyChar = Chr(97)   ' Returns 'a'.
'Output: 'a’

Esempio 3

MyChar = Chr(62)   ' Returns '>'.
'Output: '>’

Esempio 4

MyChar = Chr(37)   ' Returns '%'.
'Output: '%’

Esempio 5

Dim LineFeed, CarriageReturn
LineFeed = Chr(10)   ' Returns a linefeed character.
CarriageReturn = Chr(13)   ' Returns a carriage return character.
'LineFeed contains value as Line Feed
'CarriageReturn contains value as Carriage Return

Esempio 6

Dim CombinedChars
CombinedChars = Chr(72) & Chr(101) & Chr(108) & Chr(108) & Chr(111)   ' Returns 'Hello'.
'Output: "Hello"

Esempio 7

Dim SpecialChar
SpecialChar = Chr(64)  
'Output: '@’

Esempio 8

SpecialChar = Chr(35)    ' Returns '#'.
'Output: '#’

Esempio 9

Dim WelcomeMessage
WelcomeMessage = "Welcome" & Chr(32) & "to" & Chr(32) & "VBScript!"   ' Inserts space using Chr(32).
'Output: "Welcome to VBScript!"