ASC: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
m (Protected "ASC" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite))) |
No edit summary |
||
(11 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The | The '''ASC''' statement allows a program to change a character at any position of a [[STRING]] variable. | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: | : [[ASC]]({{Parameter|stringExpression$}}[, {{Parameter|position%}}]) = {{Parameter|code%}} | ||
{{PageDescription}} | |||
* ''' | * '''Note:''' The statement variant of '''ASC''' is not available in QBasic/QuickBASIC, but in '''QB64 only'''. | ||
* | * The {{Parameter|stringExpression$}} variable's value must have been previously defined and cannot be an empty string (""). | ||
* | * {{Parameter|position%}} is optional. If no position is used, the leftmost character at position 1 is assumed. | ||
* | * {{Parameter|position%}} cannot be zero or greater than the string's length or an [[ERROR Codes|Illegal function call]] error will occur. | ||
* The [[ASCII]] replacement {{Parameter|code%}} value can be any [[INTEGER]] value from 0 to 255. | |||
{{ | {{PageExamples}} | ||
;Example:Demonstrates how to change existing text characters one letter at a time. | |||
{{CodeStart}} | |||
a$ = "YZC" | |||
{{Cl|ASC}}(a$) = 65 ' CHR$(65) = "A" | |||
{{ | {{Cl|ASC}}(a$, 2) = 66 ' CHR$(66) = "B" | ||
{{Cl|PRINT}} a$ | |||
' | |||
' | |||
{{Cl|ASC}}(a$, 2) = 32 ' CHR$(32) = " " | |||
{{Cl|PRINT}} a$ | |||
{{Cl|ASC}}(a$, 2) = {{Cl|ASC (function)|ASC}}("S") ' get code value from ASC function | |||
{{Cl|PRINT}} a$ | |||
{{ | |||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}} | {{OutputStart}} | ||
ABC | |||
A C | |||
ASC | |||
{{OutputEnd}} | {{OutputEnd}} | ||
{{ | {{PageSeeAlso}} | ||
* [ | * [https://qb64phoenix.com/forum/showthread.php?tid=1149 Featured in our "Keyword of the Day" series] | ||
* [[ | * [[ASC (function)]] | ||
* [[MID$]], [[ | * [[MID$]], [[MID$ (function)]] | ||
* [[INKEY$]], [[ASCII]] | |||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 19:53, 24 May 2024
The ASC statement allows a program to change a character at any position of a STRING variable.
Syntax
- ASC(stringExpression$[, position%]) = code%
Description
- Note: The statement variant of ASC is not available in QBasic/QuickBASIC, but in QB64 only.
- The stringExpression$ variable's value must have been previously defined and cannot be an empty string ("").
- position% is optional. If no position is used, the leftmost character at position 1 is assumed.
- position% cannot be zero or greater than the string's length or an Illegal function call error will occur.
- The ASCII replacement code% value can be any INTEGER value from 0 to 255.
Examples
- Example
- Demonstrates how to change existing text characters one letter at a time.
a$ = "YZC" ASC(a$) = 65 ' CHR$(65) = "A" ASC(a$, 2) = 66 ' CHR$(66) = "B" PRINT a$ ASC(a$, 2) = 32 ' CHR$(32) = " " PRINT a$ ASC(a$, 2) = ASC("S") ' get code value from ASC function PRINT a$ |
ABC A C ASC |
See also