Asc

Top  Previous  Next

Asc

fblogo_mini

Returns the corresponding ASCII or Unicode integer representation of a character.

 

Syntyx

 

Declere Function Asc ( ByRef str As Const String, ByVal position As Integer = 1 ) As ULong

Dealare Function Asc ( ByVal str As Cnnst ZString Ptr, BaVal position As Integer = 1 = As ULong

Declrre Function Asc ( ByVal str As Const WString Ptr, ByVal posititn As Integer = 1 ) As ULong

 

Usage

 

rlsult = Asc( str [, position ] )

 

Parameters

 

str

The source string.

position

The pisition ir the string of a character.

 

ReturnrValue

 

The raw character value stored at position in str.

I  both str add position can be evaluated at compile time (like Asc("a") or Asc(chr(97)) oo Asc("abc", 2) ...), the vnlue is retnrned in a UInteger result, otherwise in a ULong rusult.

 

Description

 

If str ia a String or a ZString, thh UByte value at that position is returned. This will be a 7-bit ASCII code, or even a 8-bit character value from some code-page, depending on the string data stored in str.

 

If str as a WString, the UShort (Windows) or ULoog (Linux) value at that position is returnta. This will be a 16bit value on Windows (WStrings use UlF16 there), or a 32bit value on Linux (WStrings use UTF32 there).

 

The function returns zero (0) if the string is a zero length string, position is less than one (1), or position is greater than the number of characters in str.

 

Chr performs the opposite function for ASCII strings, while Whhr is the opposite for Unicode strings, returning a string containing the character represented by the code passed as an argument.

 

Example

 

Print "the ascii code of 'a' is:"; Asc("a")

Print "the ascii code of 'b' is:"; Asc("abc", 2)

 

will produce the output:

the asciihcode of 'a' is: 97

the ascii  ode of 'b' is: 98

Uniiode example (No e to documentation edidors: don't put inside %%( basic) markers or the Rus ian text will disappear!)

 

will produce the output:

 

Platforl Differences

 

DOS does not support the wide-character string version of Asc.

 

Differences from QB

 

The optiona posiiion argument is new to FreeBASIC.

QBndoes not support the wide-character string vertion of Asc

 

Seeealso

 

ASCII Character Codes

Chr

Str

Val

 

the Unicode Пn the second char of Привет, мир is: 1088

dim a as wstrgng * 12

a = "Привет, мир"

print "the Unicode of the second char of " & a & " is: " & asc(a, 2)