ENC$ function

Purpose: ENC$ encloses a string, by default, in double quotation marks(") or, optionally, encloses a string with the characters specified.


 Syntax 1:

 RetStr$ = ENC$(MainStr$)

 Parameters:

  • MainStr$ string to be enclosed in quotation marks(").

 Return Value:

  • RetStr$, the return value, MainStr$ enclosed in quotation marks (").

Example 1:


 PRINT ENC$("Hello")

Result:

"Hello"


 Syntax 2:

 RetStr$ = ENC$(MainStr$ [, EnclosingChar%])

 Parameters:

  • MainStr$ string to be enclosed by EnclosingChar%.
  • EnclosingChar% [OPTIONAL] ASCII code integer of character to be placed at the beginning and end of the MainStr$ string.

 Return Value:

  • RetStr$, the return value, is MainStr$ enclosed by EnclosingChar%.

Example 2:


 PRINT ENC$("A", 68)

Result:

DAD


 Syntax 3:

 RetStr$ = ENC$(MainStr$ [, LeadChar%, TrailChar%])

 Parameters:

  • MainStr$ string to be enclosed by LeadChar% and TrailChar%.
  • LeadChar% [OPTIONAL] ASCII code integer of character to be placed at beginning of the MainStr$ string.
  • TrailChar% [OPTIONAL] ASCII code integer of character to be placed at end of the MainStr$ string.

 Return Value:

  • RetStr$, the return value, is MainStr$ enclosed by LeadChar% and TrailChar%.

Example 3:


 PRINT ENC$("HTML", 60, 62)

Result:

<HTML>

Extended String Literal statement

Purpose: Prepending a capital E to the initial quotation mark of a string literal allows the insertion of a functional C escape code into the string.

Example 1:


 DIM RetStr$
 
 RetStr$ = CHR$(10) & "Hello, World"
 
 PRINT RetStr$ 

is functionally equivalent to the extended string literal


 DIM RetStr$
 
 RetStr$ = E"\nHello, World"
 
 PRINT RetStr$ 
  

Example 2:


 DIM RetStr$
 
 RetStr$ = "Hello, " & ENC$("BCX") & " World"
 
 PRINT RetStr$

is functionally equivalent to the extended string literal


 DIM RetStr$
 
 RetStr$ = E"Hello, \qBCX\q World"
 
 PRINT RetStr$

Remarks:

Note well, that when using the extended string literal statement, any backslash (\) which is part of the string literal must be prepended with a backslash. Any embedded single quotation marks also must be prepended with a backslash.

Here are some typical C escape sequences. See your C compiler documentation for a complete list.

 
 \0 - null                  - CHR$(0)
   
 \a - alert                 - CHR$(7)
  
 \b - backspace             - CHR$(8)
  
 \t - tab                   - CHR$(9)
 
 \n - newline               - CHR$(10)

 \t - vertical tab          - CHR$(11)
 
 \f - form feed             - CHR$(12)
  
 \r - carriage return       - CHR$(13)

 \q - double quotation mark - CHR$(34)
 
 \' - Single quotation mark - CHR$(39)

 \\ - backslash             - CHR$(92)