next up previous contents
Next: Arithmetic Operations Up: Dollar Bracket Expressions Previous: Dollar Bracket Expressions   Contents

String Operations

Table [*] lists the dollar bracket expressions that allow string operations:

Table 2: String operations.
${string} variable replacement
${:string} pure string (no parsing inside)
${& string1 string2 string3 ...} concatenation
${<-> string original replacement} string replacement

A dollar bracket expression that only contains a name is treated as variable expansion.

...
   name = GetPot
   [${name}] # meaning: [GetPot]
...
will set a section label "GetPot".

...
   [Mechanical-Engineering]
      boss       = Dr.\ Frieda\ LaBlonde
      members    = 24
      professors = 5
   []
   x = Mechanical-Engineering

   info = '${${x}/boss}: ${${x}/professors}/${${x}/members}'
...

will assign the string "Dr. Frieda La Blonde: 5/24" to the variable info. Together with sections, the dollar bracket expressions allow an elegant way to define dictionaries, such as:

...
   my-car = Citroen-2CV
   [Nicknames]
        BMW         = Beamer
        Mercedez    = Grandpa\'s\ Slide
        Volkswagen  = Beetle
        Citroen-2CV = Deuche
   []
   my-car = ${Nicknames/${my-car}}
...
uses the section "Nicknames" as dictionary. At the end the variable my-car will contain the name "Deuche" instead of "Citroen-2CV".

Some users might miss the ability to have dollar bracket expressions or white spaces inside their strings, therefore a feature is provided that enables to specify pure strings. Anything in between a ${: $\ldots$ } environment is left as is without any modification. In the following example

...
   info = ${:even expressions like ${my-car} are left as they are}
...
whitespaces and brackets are left as they are. This feature is essential when defining macros [*].

Strings can be concatenated by the ${& }-operator as in the following example

info  = ${& simple concatination without whitespaces results in a mess}
As a result of this statement, info would contain the string
"simpleconcatinationwithoutwhitespacesresultsinamess".
in other words: if you want to form a sentence consisting of words separated by whitespaces, you should either use backslashed whitespaces, quotes or pure strings. As any other normal dollar bracket expression it can contain dollar bracket expressions as part of its arguments such as in the following example:
name = FriedaBoelkenwater
network = neurology.west-wing.gov
contact-info = ${& ${:Email:} ${name} @ ${network}}
where the contact-info would be
"Email: FriedaBoelkenwater@neurology.west-wing.gov"

Another important string operation are replacements using the ${<->}-operator such as in

OBJECTS = main.o tires.o suspension.o drive-train.o cvi.o steering-system.o
PROGRAM_FILES = ${<-> ${OBJECTS} .o .cpp}
where the extensions '.o' are replaced by extension '.cpp' to get the filenames of the source code.


next up previous contents
Next: Arithmetic Operations Up: Dollar Bracket Expressions Previous: Dollar Bracket Expressions   Contents
Frank-Rene Schaefer 2002-09-14