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:
Parameters:
|
PRINT ENC$("Hello")
"Hello"
Syntax 2:RetStr = ENC$(MainStr AS STRING [, EnclosingChar AS INTEGER]) Return Value:
Parameters: |
PRINT ENC$("A", 68)
DAD
Syntax 3:RetStr = ENC$(MainStr AS STRING [, LeadChar AS INTEGER, TrailChar AS INTEGER]) Return Value:
Parameters:
|
PRINT ENC$("HTML", 60, 62)
<HTML>
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$ 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:
Parameters:
|
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:
Parameters:
|
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$
La mariée mise à nu par ses célibataires, même mise à nu
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$
"mise à nu" mise à nu
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.
The following code snippet using an E sigil
DIM RetStr$ RetStr$ = E"\nHello, World" PRINT "E" & DQ$ & "\n" & " inserts line feed character" PRINT RetStr$
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$
CHR$(10) inserts a line feed character Hello, World
This E sigil enhanced code
DIM RetStr$ RetStr$ = E"Hello, \qBCX\q World" PRINT RetStr$
Hello, "BCX" World
is functionally equivalent to
DIM RetStr$ RetStr$ = "Hello, " & ENC$("BCX") & " World" PRINT RetStr$
Hello, "BCX" World
👉 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)