[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.6 String Manipulation

string concat ( string str1, ..., strn )
Concatenates one or more strings into one string.

string format ( string pattern; val1, ..., valn ) *
Similar to the C sprintf function. pattern is a string contening conversion characters. Recognized conversion characters are :

%f
Formats a float using the style [-]ddd.ddd. Number of fractional digits depends on the precision used (see example);
%e
Formats a float using the style [-]d.ddde dd (that is, exponential notation). This is the recommended conversion for floats when precision matters;
%g
The floating point is converted to style %f or %e. Here is a snapshot from the info pages on printf():
The style used depends on the value convered; style %e will be used only if the exponent resulting from the conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional part of the result; a decimal-point character appears only if it is followed by a digit…
%d
Equivalent to %.0f, useful to format integers;
%p
Formats a point-like type (point, vector, normal) using the style [%f %f %f];
%c
Same as %p, but for colors;
%m
Formats a matrix using the style [%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f];
%s
Formats a string.

Note that all conversion characters recognise the precision specifier.

EXAMPLE
 
/* Formats a float using exponential notation */
string expo = format( "%e", sqrt(27) );

/* Formats a float, with 5 decimals in the fractional part */ 
point p = sqrt(5);
string precision5 = format( "p = %.5p", p );

/* Aligns text */
string aligned = format( "%20s", "align me please" ); 

void printf ( string pattern; val1, ..., valn ) *
Same as format() but prints the formatted string to `stdout' instead of returning a string.

float match ( string pattern, subject )
Does a string pattern match on subject. Returns 1 if pattern exists anywhere within sibjuct, 0 otherwhise. The pattern can be any standard regex(21) expression.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Aghiles Kheffache on July, 31 2003 using texi2html
3Delight 1.0.0. Copyright 2000-2003 The 3Delight Team. All Rights Reserved.