\section{STRING String Arrays}

\subsection{Usage}

FreeMat supports a \verb|string| array type that operates very
much as you would expect.  Strings are stored internally as
8-bit values, and are otherwise similar to numerical arrays in
all respects.  In some respects, this makes strings arrays
less useful than one might imagine.  For example, numerical
arrays in 2-D are rectangular.  Thus, each row in the array
must have the same number of columns.  This requirement is
natural for numerical arrays and matrices, but consider a
string array.  If one wants to store multiple strings in
a single data structure, they must all be the
same length (unlikely).  The alternative is to use a cell
array of strings, in which case, each string can be of
arbitrary length.  Most of the functions that support 
strings in a set-theoretic way, like \verb|unique| and \verb|sort|
operate on cell-arrays of strings instead of string arrays.
Just to make the example concrete, here is the old way of
storing several strings in an array:
\begin{verbatim}
--> % This is an error
--> A = ['hello';'bye']
Error: Mismatch in dimension for rows in matrix definition
--> % This is OK, but awkward
--> A = ['hello';'bye  ']

A = 

 hello
 bye  

--> % This is the right way to do it
--> A = {'hello','bye'}

A = 

 ['hello']   ['bye']   


\end{verbatim}

One important (tricky) point in FreeMat is the treatment
of escape sequences.  Recall that in \verb|C| programming, an
escape sequence is a special character that causes the output
to do something unusual.  FreeMat supports the following
escape sequences:
\begin{itemize}
\item  \verb|\t| - causes a tab to be output

\item  \verb|\r| - causes a carriage return (return to the beginning
     of the line of output, and overwrite the text)

\item  \verb|\n| - causes a linefeed (advance to next line)

\end{itemize}
FreeMat follows the \verb|Unix/Linux| convention, that a \verb|\n|
causes both a carriage return and a linefeed.  
To put a single quote into a string use the MATLAB convention
of two single quotes, not the \verb|\'| sequence.  Here is an
example of a string containing some escape sequences:
\begin{verbatim}
--> a = 'I can''t use contractions\n\tOr can I?\n'

a = 

 I can't use contractions\n\tOr can I?\n


\end{verbatim}
Now, note that the string itself still contains the \verb|\n|
characters.  With the exception of the \verb|\'|, the escape 
sequences do not affect the output unless the strings are 
put through \verb|printf| or \verb|fprintf|.  For example, if we 
\verb|printf| the variable \verb|a|, we see the \verb|\n| and \verb|\t| 
take effect:
\begin{verbatim}
--> printf(a);
I can't use contractions
	Or can I?

\end{verbatim}
The final complicating factor is on \verb|MSWin| systems.  There,
filenames regularly contain \verb|\| characters.  Thus, if you
try to print a string containing the filename 
\verb|C:\redball\timewarp\newton.txt|, the output will be mangled
because FreeMat thinks the \verb|\r|, \verb|\t| and \verb|\n| are escape
sequences.  You have two options.  You can use \verb|disp| to show
the filename (\verb|disp| does not do escape translation to be 
compatible with MATLAB).  The second option is to escape the
backslashes in the string, so that the string you send to 
\verb|printf| contains \verb|C:\\redball\\timewarp\\newton.txt|.
\begin{verbatim}
--> % disp displays it ok
--> a = 'C:\redball\timewarp\newton.txt'

a = 

 C:\redball\timewarp\newton.txt

--> % printf makes a mess
--> printf(a)
C:
edball	imewarp
ewton.txt--> % If we double up the slashes it works fine
--> a = 'C:\\redball\\timewarp\\newton.txt'

a = 

 C:\\redball\\timewarp\\newton.txt

--> printf(a)
C:\redball\timewarp\newton.txt
\end{verbatim}
