FutureBasic Logo

<<    Index    >> FutureBasic

Appendix E - String Expressions   appendix

String Expressions

A string expression is anything that can be evaluated as a string of 0 to 255 ASCII characters. A string can be expressed in any of the following ways:

I. Simple Expressions
II. Compound Expressions

A compound string expression is a list of simple string expressions separated by the concatenation operator, "+". The syntax of a compound string expression is:

simpleExpr1 + simpleExpr2 [+ simpleExpr3 ...]

The "+" operator builds a longer string by concatenating the operands. For example, consider this expression:

"Ex" + "tra" + mid$("fiction",3)

This expression has the value, "Extraction".

Note When two string expressions are separated by a data-comparison operator, such as: =; <; >, the result is a numeric expression. See Appendix D - Numeric Expressions, for more information.

Note Because the dollar sign ($) is used to designate a full 255 byte pascal string, FutureBasic must determine what you really intended to use when you dimensioned a variable. The following examples demonstrate FutureBasic's evaluation methods:

dim as Str31 z // z is a 31 byte string
dim z$;32 // z is a 31 byte string
dim z$ as Str31 // z is a 31 byte string
dim z as Str31 // z is a 31 byte string
dim as Str31 z$ // ">$" does not work. The $ overridces Str31.

Note String length errors are not reported. Instead, strings are silently truncated to the maximum length that will fit in the destination variable.

Alternative syntax for fn CFSTR()

There is a new syntax, borrowed from Objective-C, for obtaining a CF string from a string literal. In most cases the new form @"foo" is interchangeable with fn CFSTR( "foo" ), but there are differences. @"foo" uses Apple's official CFSTR macro, whereas fn CFSTR( "foo" ) uses a CFSTR emulator in the runtime. The advantage of the '@' form is that it allows escaped characters (preceded by a backslash).

dim as CFStringRef cfstr
cfstr = @"printable ascii" // same as fn CFSTR( "printable ascii" )
cfstr = @"item 1\ritem 2" // embedded return char; same as fn CFSTR( "item 1" + chr$( 13 ) + "item 2" )
cfstr = @"\"" // double-quote char; same as fn CFSTR( """" )
cfstr = @"ƒøµ" // non-ASCII chars; don't do that! Instead use fn CFSTR( "ƒøµ" )

The '@' form requires a string literal (not a string expression).