Difference between revisions of "ASC (statement)"

From QB64 Wiki
Jump to navigation Jump to search
imported>Odin
(Created page with "The '''ASC''' statement is used to change a character in a string variable into the specified '''ASC'''II code. == Syntax == '''ASC'''(stringVariable$[, position%]) = code%...")
imported>Odin
Line 5: Line 5:
  
 
== Example ==
 
== Example ==
<source>
+
<source lang="qbasic">
 
  a$ = "YZC"
 
  a$ = "YZC"
 
  ASC(a$) = 65                ' CHR$(65) = "A"
 
  ASC(a$) = 65                ' CHR$(65) = "A"

Revision as of 00:05, 18 July 2017

The ASC statement is used to change a character in a string variable into the specified ASCII code.

Syntax

ASC(stringVariable$[, position%]) = code%

Example

<source lang="qbasic">

a$ = "YZC"
ASC(a$) = 65                 ' CHR$(65) = "A"
ASC(a$, 2) = 66              ' CHR$(66) = "B"
PRINT a$ 'ABC
ASC(a$, 2) = 0               ' CHR$(0) = " " 
PRINT a$
ASC(a$, 2) = ASC("S")        ' get code value from ASC function
PRINT a$

</source>

Output:

 ABC
 A C
 ASC

Details

  • If position% isn't passed, ASC changes the left-most character.