Difference between revisions of "ASC (statement)"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
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%...")
Line 1: Line 1:
The {{KW|ASC (statement)|ASC}} statement allows a '''QB64''' program to change a character at any position of a predefined {{KW|STRING}}.
+
The '''ASC''' statement is used to change a character in a string variable into the specified '''ASC'''II code.
  
 +
== Syntax ==
 +
'''ASC'''(stringVariable$[, position%]) = code%
  
 
+
== Example ==
{{PageSyntax}}
+
<source>
::: '''ASC({{Parameter|string_expression$}}'''[, {{Parameter|position%}}]''') =''' {{Parameter|code%}}
 
 
 
 
 
{{PageDescription}}
 
* The ''string expression'' variable must have been previously defined and cannot be an empty string("").
 
* The ''position'' parameter is optional. If no position is used, the left-most position(1) is assumed.
 
* The ''position'' cannot be zero or greater than the string's length [[LEN]] or an [[ERROR Codes|Illegal function error]] will occur.
 
* The [[ASCII]] replacement ''code%'' value can be any [[INTEGER]] value from 0 to 255.
 
* Some [[ASCII]] control characters will not [[PRINT]] a character or may format the [[SCREEN]]. [[_PRINTSTRING]] can print them graphically.
 
 
 
 
 
''Example:'' Demonstrates how to change existing text characters one letter at a time.
 
{{CodeStart}}
 
 
  a$ = "YZC"
 
  a$ = "YZC"
  {{Cl|ASC (statement)|ASC}}(a$) = 65                ' CHR$(65) = "A"
+
  ASC(a$) = 65                ' CHR$(65) = "A"
  {{Cl|ASC (statement)|ASC}}(a$, 2) = 66              ' CHR$(66) = "B"
+
  ASC(a$, 2) = 66              ' CHR$(66) = "B"
  {{Cl|PRINT}} a$ 'ABC
+
  PRINT a$ 'ABC
  
  {{Cl|ASC (statement)|ASC}}(a$, 2) = 0              ' CHR$(0) = " "  
+
  ASC(a$, 2) = 0              ' CHR$(0) = " "  
  {{Cl|PRINT}} a$
+
  PRINT a$
  
  {{Cl|ASC (statement)|ASC}}(a$, 2) = {{Cl|ASC}}("S")        ' get code value from ASC function
+
  ASC(a$, 2) = ASC("S")        ' get code value from ASC function
  {{Cl|PRINT}} a$
+
  PRINT a$
{{CodeEnd}}
+
</source>
  
{{OutputStart}}
+
''Output:''
 +
<pre>
 
  ABC
 
  ABC
 
  A C
 
  A C
 
  ASC
 
  ASC
{{OutputEnd}}
+
</pre>
 
 
 
 
''See also:''
 
* [[ASC]] {{text|(function)}}
 
* [[MID$ (statement)]]
 
* [[_PRINTSTRING]]
 
* [[INKEY$]], [[ASCII]]
 
 
 
  
{{PageNavigation}}
+
== Details ==
 +
* If position% isn't passed, '''ASC''' changes the left-most character.

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>

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.