@c Copyright (C) 1993, 1994, 1995 John W. Eaton
@c This is part of the Octave manual.
@c For copying conditions, see the file gpl.texi.

@cindex strings

@node String Functions, System Utilities, Matrix Manipulation, Top
@chapter String Functions

Octave currently has a limited ability to work with strings.

@findex strcmp

The function @code{strcmp (@var{s1}, @var{s2})} compares two strings,
returning 1 if they are the same, and 0 otherwise.

@strong{Note: For compatibility with @sc{Matlab}, Octave's strcmp
function returns 1 if the strings are equal, and 0 otherwise.  This is
just the opposite of the corresponding C library function.}

@findex int2str
@findex num2str

The functions @code{int2str} and @code{num2str} convert a numeric
argument to a string.  These functions are not very flexible, but are
provided for compatibility with @sc{Matlab}.  For better control over
the results, use @code{sprintf} (@pxref{Formatted Output}).

@findex setstr

The function @code{setstr} can be used to convert a vector to a string.
Each element of the vector is converted to the corresponding ASCII
character.  For example,

@example
setstr ([97, 98, 99])
@end example

@noindent
creates the string

@example
abc
@end example

@findex undo_string_escapes

The function @code{undo_string_escapes (@var{string})} converts special
characters in strings back to their escaped forms.  For example, the
expression

@example
bell = "\a";
@end example

@noindent
assigns the value of the alert character (control-g, ASCII code 7) to
the string variable @var{bell}.  If this string is printed, the
system will ring the terminal bell (if it is possible).  This is
normally the desired outcome.  However, sometimes it is useful to be
able to print the original representation of the string, with the
special characters replaced by their escape sequences.  For example,

@example
octave:13> undo_string_escapes (bell)
ans = \a
@end example

@noindent
replaces the unprintable alert character with its printable
representation.  @xref{String Constants}, for a description of string
escapes.
