ENC$ function

Purpose:

ENC$ encloses a string, by default, in quotation marks or, optionally, encloses a string with the characters specified.

Syntax 1:

RetStr = ENC$(MainStr AS STRING)

Return Value:

  • Data type: STRING
    RetStr MainStr enclosed in quotation marks.

Parameters:

  • Data type: STRING
    MainStr The string to be enclosed in quotation marks.

Example 1:

PRINT ENC$("Hello")

Result:

"Hello"

Syntax 2:

RetStr = ENC$(MainStr AS STRING [, EnclosingChar AS INTEGER])

Return Value:

  • Data type: STRING
    RetStr The return value is MainStr enclosed by EnclosingChar.

Parameters:

  • Data type: STRING
    MainStr The string to be enclosed by EnclosingChar.
  • Data type: INTEGER
    EnclosingChar [OPTIONAL] Windows Code Page code point integer of character to be placed at the beginning and end of the MainStr string.

Example 2:

PRINT ENC$("A", 68)

Result:

DAD

Syntax 3:

RetStr = ENC$(MainStr AS STRING [, LeadChar AS INTEGER, TrailChar AS INTEGER])

Return Value:

  • Data type: STRING
    RetStr The return value is MainStr enclosed by LeadChar and TrailChar.

Parameters:

  • Data type: STRING
    MainStr The string to be enclosed by LeadChar and TrailChar.
  • Data type: INTEGER
    LeadChar [OPTIONAL] Windows Code Page code point integer of character to be placed at beginning of MainStr.
  • Data type: INTEGER
    TrailChar [OPTIONAL] Windows Code Page code point integer of character to be placed at end of MainStr.

Example 3:

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

Result:

<HTML>

Quoted Quote punctuation

Purpose:

BCX allows broad use of the Quoted Quote which is changed to DQ$ before the primary translation. The listing below demonstrates some working use cases.

$BCXVERSION "7.7.6 (08/30/2021)"

CONST DBLQT$ = """ :  PRINT DBLQT$

DIM A$ :  A$ = """ :  PRINT A$

IF "test" = """ then
 PRINT "EQUAL"
ELSE
 PRINT "NOTEQUAL"
END IF

PRINT """, """, """

IF LEFT$(A$,1) = """ THEN
 PRINT MID$(A$,1,1)
END IF

CALL PRINT_FOO(""")

SUB PRINT_FOO (A$)
 PRINT A$
END SUB

PRINT FOO$()

FUNCTION FOO$ (A$ = """, B$ = "Foo", C$ = """)
 FUNCTION = A$ + B$ + C$
END FUNCTION

WRAP$ function

Purpose:

WRAP$ will enclose a string variable or literal with specified prepending and appending strings.

Syntax:

RetStr = WRAP$(StringExpression AS STRING [, LeftSide AS STRING, RightSide AS STRING])

Return Value:

  • Data type: STRING
    RetStr The wrapped StringExpression is returned.

Parameters:

  • Data type: STRING
    StringExpression The string variable or literal to be enclosed.
  • Data type: STRING
    LeftSide, RightSide [OPTIONAL] The string variables or literals which are to prepend and append StringExpression.
    👉 By omitting both LeftSide$ and RightSide arguments, WRAP$ will wrap StringExpression using the quote character. See Example 2: below.

UNWRAP$ function

Purpose:

UNWRAP$ will remove, from a string variable or literal, specified prepending and appending strings.

Syntax:

RetStr = UNWRAP$(StringExpression AS STRING [, LeftSide AS STRING, RightSide AS STRING])

Return Value:

  • Data type: STRING
    RetStr The unwrapped StringExpression is returned.

Parameters:

  • Data type: STRING
    StringExpression The string variable or literal to be unwrapped.
  • Data type: STRING
    LeftSide, RightSide [OPTIONAL] The string variables or literals which are to be removed from the left and right sides of StringExpression.
    👉 By omitting both LeftSide$ and RightSide arguments, UNWRAP$ will remove quotes enclosing StringExpression. See Example 2: below.

Example 1:

DIM RetStr$
RetStr$ = WRAP$("mise à nu", "La mariée ", " par ses célibataires, même")
PRINT RetStr$
RetStr$ = UNWRAP$(RetStr$, "La mariée ", " par ses célibataires, même")
PRINT RetStr$

Result:

La mariée mise à nu par ses célibataires, même
mise à nu

Example 2:

In the following example, by omitting the LeftSide$, RightSide arguments, WRAP$ will enclose StringExpression with quotation marks and UNWRAP will remove them.


DIM RetStr$
RetStr$ = WRAP$("mise à nu")
PRINT RetStr$
RetStr$ = UNWRAP$(RetStr$)
PRINT RetStr$

Result:

"mise à nu"
mise à nu

E sigil

Purpose:

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

Example 1:

The following code snippet using an E sigil

DIM RetStr$
RetStr$ = E"\nHello, World"
PRINT "E" & DQ$ & "\n" & " inserts line feed character"
PRINT RetStr$

Result:

E"\n inserts line feed character

Hello, World

is functionally equivalent to this code


DIM RetStr$
RetStr$ = CHR$(10) & "Hello, World"
PRINT "CHR$(10) inserts a line feed character"
PRINT RetStr$

Result:

CHR$(10) inserts a line feed character

Hello, World

Example 2:

This E sigil enhanced code

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

Result:

Hello, "BCX" World

is functionally equivalent to


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

Result:

Hello, "BCX" World

Remarks:

👉 When using the E sigil, 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 - Quotation mark  - CHR$(34)

\' - Apostrophe      - CHR$(39)

\\ - Backslash       - CHR$(92)