Repository navigation
Asc
Home › String Functions › Asc
Returns the character code at a position in a string.
Declare Function Asc ( ByRef str As Const String, ByVal position As Integer = 1 ) As ULong
Declare Function Asc ( ByVal str As Const ZString Ptr, ByVal position As Integer = 1 ) As ULong
Declare Function Asc ( ByVal str As Const WString Ptr, ByVal position As Integer = 1 ) As ULongstrposition
If str is a String or a ZString, the 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 is a WString, the UShort (Windows) or ULong (Linux and macOS) value at that position is returned. This will be a 16bit value on Windows (WStrings use UTF16 there), or a 32bit value on Linux and macOS (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 WChr is the opposite for Unicode strings, returning a string containing the character represented by the code passed as an argument.
The raw character value stored at position in str.
If both str and position can be evaluated at compile time (like Asc("a") or Asc(chr(97)) or Asc("abc", 2) ...), the value is returned in a UInteger result, otherwise in a ULong result.
result = Asc( str [, position ] )
- DOS does not support the wide-character string version of
Asc.
- The optional
positionargument is new to FreeBASIC. - QB does not support the wide-character string version of
Asc
Print "the ascii code of 'a' is:"; Asc("a")
Print "the ascii code of 'b' is:"; Asc("abc", 2)will produce the output:
the ascii code of 'a' is: 97
the ascii code of 'b' is: 98Unicode example (Note to documentation editors: don't put inside %%(qbasic) markers or the Russian text will disappear!)
dim a as wstring * 12
a = "Привет, мир"
print "the Unicode of the second char of " & a & " is: " & asc(a, 2)Category: String Functions
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing